Scaling a Custom View

Nathan Sokalski 4,121 Reputation points
2022-10-18T05:24:19.617+00:00

I have a custom view (I inherit from View) that I want the user to be able to scale using layout_width & layout_height. I am not sure if this is something that should be done in OnMeasure(), OnDraw(), or somewhere else. If I change the values in SetMeasuredDimension() in OnMeasure(), it changes the boundaries of the layout, but the items drawn on the Canvas in OnDraw() remain the same size (although the View may be cropped or padded based on these values). I know that the user can resize the View using the scaleX & scaleY properties in XML, but this is very inefficient. How can I adjust the size of the View based on layout_width & layout_height?

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