Overriding OnMeasure When Inheriting From RadialProgressView

Nathan Sokalski 4,116 Reputation points
2022-01-29T04:46:18.257+00:00

I am overriding the OnMeasure method of a View that inherits from RadialProgress.RadialProgressView (this is the only method I override). Here is the override code:

protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
    int height = View.MeasureSpec.GetSize(heightMeasureSpec);
    if (height)
    {
        System.Diagnostics.Debug.WriteLine($"OnMeasure   Checkpoint 1   {height}");
        base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
    }
    else
    {
        System.Diagnostics.Debug.WriteLine($"OnMeasure   Checkpoint 2   {height}");
        //this.SetMeasuredDimension(height,height);
        this.SetMeasuredDimension(400, 400);
    }
}

On the first several passes, View.MeasureSpec.GetSize(heightMeasureSpec) returns a value of 0, and then on the final pass it returns a non-zero value. If my code contained only the following code:

this.SetMeasuredDimension(400, 400);

it would work fine, however, I need to dynamically obtain the height (which is the value returned by View.MeasureSpec.GetSize(heightMeasureSpec) on the final pass). As you can see in my code, I detect whether this value is equal to 0. What can I do to dynamically obtain the height & call SetMeasuredDimension? (NOTE: In my xml layout this View has android:layout_rowWeight="1")

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,294 questions
0 comments No comments
{count} votes