3

I am learning a custom component, and I find some difference in the view and viewgroup for the method onMeasure().For example, someone calls super.onMeasure, someone uses setMeasuredDimension at the end. Where is a difference? And measureChildren() means what?

This is the first time I've come this community, hope get the answer I wanted, thanks.

Curry Cao
  • 31
  • 2

1 Answers1

0

super.onMeasure()

This is used when you want to leave the measuring of your custom component to the super class you are extending from. For example, lets say you are building a custom TextView for multi colored texts. You really don't want to override the onMeasure() implementation of TextView because you are not dealing with the width and height of the text. So you can call super.onMeasure() and leave the measuring to TextView.

setMeasuredDimension()

In case, you do have to override onMeasure(), you use setMeasuredDimension() to tell the android view rendering system the final calculated width and height of your custom view. This will be used by the view system for rendering your view.

measureChildren() It tells the children of this ViewGroup to measure themselves using the givenMeasureSpec.

A very nice discussion here.

Community
  • 1
  • 1
Pravin Sonawane
  • 1,803
  • 4
  • 18
  • 32