博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
View
阅读量:6121 次
发布时间:2019-06-21

本文共 3467 字,大约阅读时间需要 11 分钟。

hot3.png

 

//final 不可继承所有View测量都会调用public final void measure(int widthMeasureSpec, int heightMeasureSpec) {        boolean optical = isLayoutModeOptical(this);        if (optical != isLayoutModeOptical(mParent)) {            Insets insets = getOpticalInsets();            int oWidth  = insets.left + insets.right;            int oHeight = insets.top  + insets.bottom;            widthMeasureSpec  = MeasureSpec.adjust(widthMeasureSpec,  optical ? -oWidth  : oWidth);            heightMeasureSpec = MeasureSpec.adjust(heightMeasureSpec, optical ? -oHeight : oHeight);        }        // Suppress sign extension for the low bytes        long key = (long) widthMeasureSpec << 32 | (long) heightMeasureSpec & 0xffffffffL;        if (mMeasureCache == null) mMeasureCache = new LongSparseLongArray(2);        final boolean forceLayout = (mPrivateFlags & PFLAG_FORCE_LAYOUT) == PFLAG_FORCE_LAYOUT;        // Optimize layout by avoiding an extra EXACTLY pass when the view is        // already measured as the correct size. In API 23 and below, this        // extra pass is required to make LinearLayout re-distribute weight.        final boolean specChanged = widthMeasureSpec != mOldWidthMeasureSpec                || heightMeasureSpec != mOldHeightMeasureSpec;        final boolean isSpecExactly = MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY                && MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.EXACTLY;        final boolean matchesSpecSize = getMeasuredWidth() == MeasureSpec.getSize(widthMeasureSpec)                && getMeasuredHeight() == MeasureSpec.getSize(heightMeasureSpec);        final boolean needsLayout = specChanged                && (sAlwaysRemeasureExactly || !isSpecExactly || !matchesSpecSize);        if (forceLayout || needsLayout) {            // first clears the measured dimension flag            mPrivateFlags &= ~PFLAG_MEASURED_DIMENSION_SET;            resolveRtlPropertiesIfNeeded();            int cacheIndex = forceLayout ? -1 : mMeasureCache.indexOfKey(key);            if (cacheIndex < 0 || sIgnoreMeasureCache) {                // measure ourselves, this should set the measured dimension flag back                onMeasure(widthMeasureSpec, heightMeasureSpec);                mPrivateFlags3 &= ~PFLAG3_MEASURE_NEEDED_BEFORE_LAYOUT;            } else {                long value = mMeasureCache.valueAt(cacheIndex);                // Casting a long to int drops the high 32 bits, no mask needed                setMeasuredDimensionRaw((int) (value >> 32), (int) value);                mPrivateFlags3 |= PFLAG3_MEASURE_NEEDED_BEFORE_LAYOUT;            }            // flag not set, setMeasuredDimension() was not invoked, we raise            // an exception to warn the developer            if ((mPrivateFlags & PFLAG_MEASURED_DIMENSION_SET) != PFLAG_MEASURED_DIMENSION_SET) {                throw new IllegalStateException("View with id " + getId() + ": "                        + getClass().getName() + "#onMeasure() did not set the"                        + " measured dimension by calling"                        + " setMeasuredDimension()");            }            mPrivateFlags |= PFLAG_LAYOUT_REQUIRED;        }        mOldWidthMeasureSpec = widthMeasureSpec;        mOldHeightMeasureSpec = heightMeasureSpec;        mMeasureCache.put(key, ((long) mMeasuredWidth) << 32 |                (long) mMeasuredHeight & 0xffffffffL); // suppress sign extension    }

 

 

 

转载于:https://my.oschina.net/leonardtang/blog/866500

你可能感兴趣的文章
让div固定在某个位置
查看>>
Java开发环境Docker镜像
查看>>
从无到有,WebService Apache Axis2初步实践
查看>>
任务调度(一)——jdk自带的Timer
查看>>
UIKit框架(15)PCH头文件
查看>>
整理看到的好的文档
查看>>
MAC 下安装dnsmasq来搭建dns服务器
查看>>
system center 详解
查看>>
zabbix企业应用之监控mysql 5.6版本
查看>>
我的友情链接
查看>>
Web语音处理 - Web Audio API & WebRTC
查看>>
org.tinygroup.validatecomponent-流程校验组件
查看>>
Linux磁盘管理和文件系统管理
查看>>
我的友情链接
查看>>
Jumpserver堡垒机安装配置全过程(二)-配置
查看>>
iOS layer
查看>>
我的友情链接
查看>>
第一次自己写存储过程去进行设备录入——存做纪念
查看>>
我的友情链接
查看>>
PTR的故事
查看>>