您的位置:首页 > 其它

LinearLayout测量过程疑问

2015-07-03 17:21 357 查看
疑问:

在LinearLayout的测量方法measureHorizontal里,有个地方存在疑问,widthMode和isExactly赋初值之后,在后面的for循环整个流程里,其值并没有变化,按这个逻辑,如果下面第一份if语句能进去,第二个if则应该一直为true,else语句是永远不会执行的,但为何要这么写呢?

void measureHorizontal(int widthMeasureSpec, int heightMeasureSpec) {

final int widthMode = MeasureSpec.getMode(widthMeasureSpec);

final int heightMode = MeasureSpec.getMode(heightMeasureSpec);



final boolean isExactly =
widthMode == MeasureSpec.EXACTLY;



for (int i = 0; i < count; ++i) {



if (widthMode == MeasureSpec.EXACTLY && lp.width == 0 && lp.weight > 0) {

// Optimization: don't bother measuring children who are going to use

// leftover space. These views will get measured again down below if

// there is any leftover space.

if (isExactly) {

mTotalLength += lp.leftMargin + lp.rightMargin;

} else {

final int totalLength = mTotalLength;

mTotalLength = Math.max(totalLength, totalLength +

lp.leftMargin + lp.rightMargin);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: