Home » Android » layout – Do onMeasure in Android returns Size including padding and margin?

layout – Do onMeasure in Android returns Size including padding and margin?

Posted by: admin May 14, 2020 Leave a comment

Questions:

I am working on a Custom Component and would like to know if onMeasure called on children would return width and height of the child including padding and margin of it?

How to&Answers:

The sizes passed in onMeasure includes the padding, but not the margin.

So, while implementing your onMeasure you should keep in mind:

  • The padding.
  • The minimum width and minimum height of our view (use getSuggestedMinimumWidth() and getSuggestedMinimumHeight() to get those values).
  • The widthMeasureSpec and heightMeasureSpec which are the requirements passed to us by the parent.

Ref: Custom View: mastering onMeasure | Lorenzo Quiroli