Sign in Go Pro

Custom Views and ViewGroups

Custom ViewGroups (Part 4): Implementing onMeasure

This lesson is for PRO members.

Upgrade today to get access to all the PRO lessons.

Unlock this lesson



In this lesson, we will implement the `onMeasure` in our custom `ViewGroup` in order to properly size both the child views and the `ViewGroup` itself. - How child views and the space that each takes up horizontally and vertically affects the space available for other views - How to track the width used and height used in a `ViewGroup` as we measure views - How to use `measureChildWithMargins` to do the hard work of calculating child `MeasureSpec` values and calling `measure` on that child - How to include the child's `LayoutParams` margin values in the calculations - How to calculate the overall measured width and height of the custom `ViewGroup` and call `setMeasuredDimension`

Lessons in Custom Views and ViewGroups