Android API之onLayout, onMeasure
2013-12-24 11:12
561 查看
/article/4847927.html
android.view.ViewGroup
protected void onLayout(boolean changed, int l, int t, int r, int b)
执行layout操作时调用onLayout方法。View要给它的每个Child设定size和position。拥有Children的子类需要重写onLayout方法并且调用每个Child的layout方法。
参数changed表示view的size或position发生变化。参数l, t, r, b分别表示相对于parent的left, top, right, bottom position。
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
测量View及其Content,确定measuredWidth和measuredHeight。在方法measure(int, int)中调用。重写onMeasure方法时,需要调用方法setMeasuredDimension(int, int),存储View的measuredWidth和measuredHeight。若存储失败,方法measure(int, int)会抛出异常IllegalStateException。可以调用super.onMeasure(int,
int)方法。
除非MeasureSpec准许更大的size,否则measure的默认实现是background size。子类重写onMeasure(int, int)提供Content的更佳测量。如果onMeasure被重写,子类必须保证measuredWidth和measuredHeight至少是view的minHeight和minWidth。minHeight/Width通过getSuggestedMinimumHight/Width()获取。
参数width/heightMeasureSpec表示parent强加的horizontal/vertical space要求。
void android.view.ViewGroup.layout(int l, int t, int r, int b)
给view及其descendants设定size和position。它正是layout机制的第2个步,每个parent调用它的chlidren的layout操作。使用在measure阶段测量得到的size和position数据完成layout操作。拥有child的子类必须重写onLayout方法,调用每个child的layout操作。
void android.view.ViewGroup.measureChildren(int widthMeasureSpec, int heightMeasureSpec)
请View的所有children测量themseles, 测量依据是View的MeasureSpec和padding。忽略处于GONE状态的children,是否GONE状态由getChildMeasureSpec来确定。
参数width/heightMeasureSpec表示view的width/height要求。
android.view.ViewGroup
protected void onLayout(boolean changed, int l, int t, int r, int b)
执行layout操作时调用onLayout方法。View要给它的每个Child设定size和position。拥有Children的子类需要重写onLayout方法并且调用每个Child的layout方法。
参数changed表示view的size或position发生变化。参数l, t, r, b分别表示相对于parent的left, top, right, bottom position。
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
测量View及其Content,确定measuredWidth和measuredHeight。在方法measure(int, int)中调用。重写onMeasure方法时,需要调用方法setMeasuredDimension(int, int),存储View的measuredWidth和measuredHeight。若存储失败,方法measure(int, int)会抛出异常IllegalStateException。可以调用super.onMeasure(int,
int)方法。
除非MeasureSpec准许更大的size,否则measure的默认实现是background size。子类重写onMeasure(int, int)提供Content的更佳测量。如果onMeasure被重写,子类必须保证measuredWidth和measuredHeight至少是view的minHeight和minWidth。minHeight/Width通过getSuggestedMinimumHight/Width()获取。
参数width/heightMeasureSpec表示parent强加的horizontal/vertical space要求。
void android.view.ViewGroup.layout(int l, int t, int r, int b)
给view及其descendants设定size和position。它正是layout机制的第2个步,每个parent调用它的chlidren的layout操作。使用在measure阶段测量得到的size和position数据完成layout操作。拥有child的子类必须重写onLayout方法,调用每个child的layout操作。
void android.view.ViewGroup.measureChildren(int widthMeasureSpec, int heightMeasureSpec)
请View的所有children测量themseles, 测量依据是View的MeasureSpec和padding。忽略处于GONE状态的children,是否GONE状态由getChildMeasureSpec来确定。
参数width/heightMeasureSpec表示view的width/height要求。
相关文章推荐
- Android API之onLayout, onMeasure
- 自定义View(三) 之 onMeasure() onLayout() onDraw()
- onmeasure被调用了但是onlayout没有被调用
- FlowLayout详解(一)——onMeasure()与onLayout()
- onMeasure(),onLayout(),onDraw(),invalidate()方法详解
- onMeasure、onLayout以及onSizeChanged方法的回调时机和回调顺序
- onMeasure,onLayout,onDraw执行顺序问题
- onFinishInflate()、onMeasure()、onLayout()的调用顺序
- FlowLayout详解(一)——onMeasure()与onLayout()
- Android API 中文(76)——AdapterView.OnItemLongClickListener
- Auto Layout on iOS Versions prior to 6.0
- 源码分析:onAttach, onMeasure, onLayout, onDraw 的顺序。
- Android下如何理解onMeasure,onLayout的过程
- Change Fragment layout on orientation change
- Android自定义控件之onLayout
- Android onLayout、layout区别
- [译文]On having layout
- Android之OnMeasure、OnLayout、OnDraw
- Auto Layout on iOS Versions prior to 6.0 解决办法
- Android layout、onLayout 一些简要说明