LinearLayout.onMeasure-設定LinearLayout的高度

weixin_34138377發表於2016-05-22
    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的寬高

相關文章