This is the last part of the HenCoder Layout section: Rewrite onMeasure() and onLayout() to customize the Layout’s internal Layout.

Introduction to the

Although this period is a long time from the previous period, it is mainly for my personal reasons, rather than because the content of this period is difficult. The content of this issue is relatively simple, mainly some concepts and principles of things, practical operation is very easy, so the same as the previous period, the main video is about the same:

If you can’t see the video, you can click here and go directly to station B; If you’re overseas, you can watch it on YouTube here.

conclusion

The article in this issue is still a summary. But this is mainly because I’ve been going through a lot lately…

Custom Layout Specifies the way to customize the internal Layout

  1. rewriteonMeasure()To calculate the internal layout
  2. rewriteonLayout()To put the subview

Override the three steps of onMeasure() :

  1. To call each child Viewmeasure()To calculate the size of the child View
  2. Calculates the position of the child View and saves the position and size of the child View
  3. Calculate your own measurements and use themsetMeasuredDimension()save

The key to calculating the size of a child View

The key to calculating the size of a child View is the calculation of the two MeasureSpec parameters of the measure() method.

Child View MeasureSpec = child View MeasureSpec = child View

  • Combined with developer requirements (XMLlayout_Header properties) and your own available space (your own size upper limit – used size)
  • Size upper limit according to your ownMeasureSpecIn mode
    • EXACTLY/AT_MOST: Size upper limit isMeasureSpecIn thesize
    • UNSPECIFIED: The size is UNSPECIFIED

How to override onLayout()

Call layout() of each child View in onLayout() to save its position and size.

Practice project

There are still no exercises for this period.

Slow down production statement

While working on HenCoder has been getting better and better lately, work and personal issues have been piling up. Due to personal limitations, HenCoder will then be forced to slow down even further.

Call…… I’ll see you next time, sometime in the future!

Feel great?

So just keep an eye on it? Left left left