MeasureSpec 是什么?

博客提及了‘measure(测量)’和‘specification(规格)’相关内容,属于信息技术领域概念。
 measure 测量 specification 规格。
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); int measureWidth = MeasureSpec.getSize(widthMeasureSpec); int measureHeight = MeasureSpec.getSize(heightMeasureSpec); int measureWidthMode = MeasureSpec.getMode(widthMeasureSpec); int measureHeightMode = MeasureSpec.getMode(heightMeasureSpec); // 每一行的宽和高 int lineWidth = 0; int lineHeight = 0; // FlowLayout的宽和高,换行时需要不断更新值 int width = 0; int height = 0; int count = getChildCount(); for (int i = 0; i < count; i++) { View child = getChildAt(i); measureChild(child, widthMeasureSpec, heightMeasureSpec); MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams(); int childWidth = child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin; int childHeight = child.getMeasuredHeight() + lp.bottomMargin + lp.topMargin; if (lineWidth + childWidth > measureWidth) { // 换行 // 将当前行宽与目前最大的行宽进行比较 计算出最新的最大行宽 width = Math.max(lineWidth, width); height += lineHeight; // 计算出新起那一行的宽和高 lineWidth = childWidth; lineHeight = childHeight; } else { lineWidth += childWidth; // 取最大值高度 lineHeight = Math.max(lineHeight, childHeight); } //处理最后一行 最后一行不存在超出width范围的场景 todo if (i == count - 1) { width = Math.max(lineWidth, width); height += lineHeight; } } setMeasuredDimension(measureWidthMode == MeasureSpec.EXACTLY ? measureWidth : width, measureHeightMode == MeasureSpec.EXACTLY ? measureHeight : height); } 在换行场景下, height += lineHeight;最终得到的height准确吗
最新发布
09-15
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值