android View类及View派生类的 measure/layout 相关方法实现 调查
来源:互联网 发布:淘宝电话改差评技巧 编辑:程序博客网 时间:2024/05/08 12:10
View:
public final void measure(int widthMeasureSpec, int heightMeasureSpec) {//有实现,final的 祖祖辈辈用一套}这个方法注释也建议子类不要覆盖, 覆盖onLayout() * Derived classes should not override this method. * Derived classes with children should override * onLayout. In that method, they should * call layout on each of their children.public void layout(int l, int t, int r, int b) {//有实现}protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // 无脑实现 setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec), getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec));}protected void onLayout(boolean changed, int left, int top, int right, int bottom) { //毛都没有}
ViewGroup extends View:
ViewGroup是一个抽象类,唯一的一个abstract方法就是onLayout().
使用父类的measure() 和 onMeasure()// 又被覆盖成abstarct了....,为了保证后面viewGroup派生类实现自己的排布法,也是一个提醒。@Overrideprotected abstract void onLayout(boolean changed, int l, int t, int r, int b);@Override有自己实现public final void layout(int l, int t, int r, int b) { if (!mSuppressLayout && (mTransition == null || !mTransition.isChangingLayout())) { if (mTransition != null) { mTransition.layoutChange(this); } super.layout(l, t, r, b); } else { // record the fact that we noop'd it; request layout when transition finishes mLayoutCalledWhileSuppressed = true; }}
FrameLayout extends ViewGroup:
measure 和 layout 继承父类实现,实现了自己的onMeasure() 和 onLayout(),这也是android所希望的方式,自己的定制化实现都放在onMeasure() 和 onLayout()中.
LinearLayout extends ViewGroup:
measure 和 layout 继承父类实现,实现了自己的onMeasure() 和 onLayout(),这也是android所希望的方式,自己的定制化实现都放在onMeasure() 和 onLayout()中.
AdapterView extends ViewGroup:
另外,AdapterView因为定位于Adapter来驱动视图变化,因此他的所有Add/RemoveView() 都不可用,会抛异常.
可用的是Add/RemoveViewInLayout()<不会触发requestLayout>
measure() onMeasure() layout() 继承父类ViewGroup @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { // 简单实现 mLayoutHeight = getHeight(); }
AbsListView extends AdapterView<ListAdapter>
measure() layout() 继承父类AdapterView<ListAdapter>自己实现onMeasure() 和 onLayout()
ViewGroup 里面有几个方法:
protected void measureChildren(int widthMeasureSpec, int heightMeasureSpec)
protected void measureChild(View child, int parentWidthMeasureSpec, int parentHeightMeasureSpec)
protected void measureChildWithMargins(View child, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed)
这几个方法,ViewGroup本身没有使用,是留给子类使用的.
invalidate() 一般不会触发 onLayout 和 onMeasure (除非之前forceLayout过), 而Layout()中的setFrame() 在尺寸变化的时候会调用 invalidate() (这只是其实一例,还有别的用invalidate的情况).
这几个方法是在 ViewGroup的实现类 的onMeasure()中被使用的,ViewGroup本身和View不会使用.
- android View类及View派生类的 measure/layout 相关方法实现 调查
- 关于View的measure,layout方法
- View 的 measure 方法
- view 的 measure方法
- Android View的Measure
- Android View绘制:measure,layout和draw
- View的工作原理:measure、layout、draw
- View的measure, layout, draw整个过程
- android view的讲解 之 view的工作流程(measure,layout,draw)(二)
- View的工作原理之View的measure、layout、draw
- android 定制 View派生类
- Android View measure (二) 自定义UI控件measure相关
- measure,layout,draw的相关方法
- android中View.measure方法的源码注解
- Android中View绘制流程:measure过程,layout过程
- Android自定义view之measure、layout、draw三大流程
- Android自定义view浅谈(二) measure layout 和draw
- android中View.measure方法详解
- HDU 1565 方格取数(1)
- 第十六周 项目2.1.1 字符串str1和字符串str2连接
- java 中的break 和 continue
- Ubuntu下挂载Win8磁盘
- 正则表达式基本语法(长期不断更新)
- android View类及View派生类的 measure/layout 相关方法实现 调查
- file的fread函数使用
- AWS 技术峰会
- String类split函数的特殊分隔符
- 第十六周 项目2.1.2 去除字符串str中特定的字符才,结果仍保存在原字符串中
- iOS 中英文混合排序
- CSDN排行榜
- 要读的书
- Dalvik 与 JVM的区别 (一)