2024年安卓最新android 中 getWidth() 和getMeasureWidth()的区别(3),2024年最新网易面试题 java

推荐学习资料

  • Android进阶学习全套手册

  • Android对标阿里P7学习视频

  • BAT TMD大厂Android高频面试题

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

/**

  • The distance in pixels from the left edge of this view’s parent

  • to the left edge(边缘) of this view.

  • {@hide}

  • 当前view的做左边缘到父view左便于的像素距离
    /
    protected int mLeft;
    /
    *

  • The distance in pixels from the left edge of this view’s parent

  • to the right edge of this view.

  • {@hide}

  • 同理
    */
    protected int mRight;

  • 所以,这只是一个通过加减得到的一个相对值,并不是真正测量得到的尺寸;

getMeasuredWidth
  • 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;
}

  • 这里有两个变量,一个是 mMeasuredWidth,一个是 MEASURED_SIZE_MASK

/**

  • Bits of {@link #getMeasuredWidthAndState()} and
  • {@link #getMeasuredWidthAndState()} that provide the actual(真实的) measured size.
    */
    public static final int MEASURED_SIZE_MASK = 0x00ffffff;

MEASURED_SIZE_MASK 是一个16进制的树,这里需要说明一下,view 的测量结果,它封装在:MeasureSpec类中,主要包含测量结果测量模式,有三种,分别是:MeasureSpec.UNSPECIFIED,MeasureSpec.AT_MOST,MeasureSpec.EXACTLY,MeasureSpec通过makeMeasureSpec() 方法将模式大小,封装在了一起,一个int值,高2位是测量模式,低30位是view的尺寸;

mMeasuredWidth 的值是怎么设置上的;

  • 流程子view 的 onMeasure()---->setMeasuredDimension()----->setMeasuredDimensionRaw()

  • 第一步 :setMeasuredDimension();

/**

  • This method must be called by {@link #onMeasure(int, int)} to store the

  • measured width and measured height. Failing to do so will trigger an
  • exception at measurement time.
  • 这个方法必须在onMeasure(int, int)中调用
  • @param measuredWidth The measured width of this view. May be a complex
  • bit mask as defined by {@link #MEASURED_SIZE_MASK} and
  • {@link #MEASURED_STATE_TOO_SMALL}.
  • @param measuredHeight The measured height of this view. May be a complex
  • bit mask as defined by {@link #MEASURED_SIZE_MASK} and
  • {@link #MEASURED_STATE_TOO_SMALL}.
    */
    protected final void setMeasuredDimension(int measuredWidth, int measuredHeight) {
    boolean optical = isLayoutModeOptical(this);
    if (optical != isLayoutModeOptical(mParent)) {
    Insets insets = getOpticalInsets();
    int opticalWidth = insets.left + insets.right;
    int opticalHeight = insets.top + insets.bottom;

measuredWidth += optical ? opticalWidth : -opticalWidth;
measuredHeight += optical ? opticalHeight : -opticalHeight;
}
// 设置view的原始尺寸
setMeasuredDimensionRaw(measuredWidth, measuredHeight);

新的开始

改变人生,没有什么捷径可言,这条路需要自己亲自去走一走,只有深入思考,不断反思总结,保持学习的热情,一步一步构建自己完整的知识体系,才是最终的制胜之道,也是程序员应该承担的使命。

《系列学习视频》

《系列学习文档》

《我的大厂面试之旅》

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

et/topics/618156601)**

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值