基于4.4 code:

View.java:

    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {        setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec),                getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec));    }............................................................................. protected final void setMeasuredDimension(int measuredWidth, int measuredHeight) { ..................................................................... mMeasuredWidth = measuredWidth; mMeasuredHeight = measuredHeight; mPrivateFlags |= PFLAG_MEASURED_DIMENSION_SET; }............................................................................../** * Like {@link #getMeasuredWidthAndState()}, but only returns the * raw width component (that is the result is masked by * {@link #MEASURED_SIZE_MASK}). * * @return The raw measured width of this view. */ public final int getMeasuredWidth() { return mMeasuredWidth & MEASURED_SIZE_MASK; }

之前光顾看基类ViewGroup了,结果发现 View的onMeasure中通过setMeasuredDimension()设置的View的mMeasuredWidth/Height 在 ViewGroup中根本

没有被用到,很是疑惑,感觉measure的意义没了,后来看了细化出来的FrameLayout等layout类,才发现,在这些真正的按照某种规则排布子View的类中

在onMeasure和onLayout中都是会用到子view的getMeasuredWidth/height()的,其实看到ViewGroup的onLayout是抽象函数时,应该有所察觉的。

而MeasuredWidth/Height 也基本只有在父View onMeasure/onLayout的情况下有用。

在子view的layout被调用时,会调到setFrame(l, t, r, b),这个函数才是真正的设置了View的尺寸,不一定就是之前measure时的MeasuredHeight。


更多相关文章

  1. 箭头函数的基础使用
  2. Python技巧匿名函数、回调函数和高阶函数
  3. 基于Android的邮件收发
  4. 《Android(安卓)基础(十)》FloatingActionButton
  5. Android(安卓)MenuItem 设置文字颜色-TextColor的设置
  6. Android中播放视频
  7. android通知栏提示
  8. Android(安卓)解压zip文件
  9. android进度条对话框小例子

随机推荐

  1. 简单android联网
  2. android LOG机制
  3. Android中如何让图片自适应控件的大小
  4. Android8.0 Rild守护进程
  5. Android进阶高手(四)终谈GPS
  6. Android精品资源分享站
  7. Android(安卓)4.0 suspend/resume (kernel
  8. Android招式之美,学习笔记,开篇
  9. Android性能测试小工具Emmagee
  10. Android(安卓)- Attr、Style、Theme浅析