What is onMeasure Custom View in Android?
In Android, there are many views available already, using them any developer creates a UI of an android application, that a developer wants to create. In-Built Views are the following:
A user interfaces element that displays text to the user.
A user interfaces element for entering and modifying text.
A user interfaces element the user can tap or click to perform an action.
Displays image resources, for example, Bitmap or Drawable resources.
There are many more inBuilt views, layouts, and ViewGroups.
Visit it to know more: Android View
If any developer wants to create a UI which have views according to his thought. That created view is called CUSTOM VIEW. Android gives a powerful model for building your UI, based on the fundamental layout classes.
We want to draw a View, first, we need to know the size of the View, and how the system draws it, and then tell the system, that this process is done in the onMeasure() method.
protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)
So, basically to decide the size of the view by the developer we use the onMeasure() method. we do overriding onMeasure to get the desired size of the view. When onMeasure is called you get widthMeasureSpec and heightMeasureSpec. This Spec is a way for the parent view to informing you about the requested size and size mode for your view. A size mode is a constraint the parent view sets for its child.
Below is the example of onMeasure overriding Use:
Please Login to comment...