LinearLayout.onMeasure-设置LinearLayout的高度

96
None_Ling
2016.05.22 21:42* 字数 55
    if (!allFillParent && widthMode != MeasureSpec.EXACTLY) {
        maxWidth = alternativeMaxWidth;
    }
    
    maxWidth += mPaddingLeft + mPaddingRight;

    // Check against our minimum width
    maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth());
    
    setMeasuredDimension(resolveSizeAndState(maxWidth, widthMeasureSpec, childState),
            heightSizeAndState);

    if (matchWidth) {
        forceUniformWidth(count, heightMeasureSpec);
    }
  1. 判断allFillParent以及widthMode,如果满足的话,那么maxWidth则设为alternativeMaxWidth
  2. maxWidth再加上左右的间距
  3. 比较和背景图的大小
  4. 通过resolveSizeAndState获取widthMeasureSpec,通过setMeasuredDimension设置LinearLayout的宽高
Android UI
Web note ad 1