onMeasure() is a method to calculate component boundary before drawing the component. So, when we want some additional dimension unit in width / height we have to take it in this method. The declaratin of this method is just like below:To inherit from View class we have to consider on minimal 2 method after its Constructor. The two methods are onMeasure() and onDraw() method. These two method take an important role in viewing the component on the screen.
protected void onMeasure(int widthMeasureSpec,
where widthMeasureSpec and heightMeasureSpec is for width and height measure spec.
onDraw() is a method for drawing component.
Ancestor method contains empty code, so we have to draw our component in this method. The declaration of this method is like below:
protected void onDraw(Canvas canvas)
For clearly source, please take a look at the source code attached to this document.
Was This Information Help ?