view设置gone的时候getHeight()的值

view设置gone的时候getHeight()的值

    public final int getHeight() {

        return mBottom - mTop;

    }

是由mBottom和mTop决定的

假定父控件parentView为linearLayout,子控件childView为View;

追踪到onLayout

    protected void onLayout(boolean changed, int l, int t, int r, int b) {

        if (mOrientation == VERTICAL) {

            layoutVertical(l, t, r, b);

        } else {

            layoutHorizontal(l, t, r, b);

        }

    }

2选1,看layoutVertical

void layoutVertical(int left, int top, int right, int bottom) {

...

else if (child.getVisibility() != GONE) {

...

setChildFrame(child, childLeft, childTop + getLocationOffset(child),childWidth, childHeight);

...

}

...

}

GONE的时候,并不会调用setChildFrame,getHeight的值也就不会变

    private void setChildFrame(View child, int left, int top, int width, int height) {        

        child.layout(left, top, left + width, top + height);

    }

继续往下走,childView的layout

    public void layout(int l, int t, int r, int b) {

...

        boolean changed = isLayoutModeOptical(mParent) ?setOpticalFrame(l, t, r, b) : setFrame(l, t, r, b);

...

}


    private boolean setOpticalFrame(int left, int top, int right, int bottom) {

        Insets parentInsets = mParent instanceof View ?

                ((View) mParent).getOpticalInsets() : Insets.NONE;

        Insets childInsets = getOpticalInsets();

        return setFrame(

                left   + parentInsets.left - childInsets.left,

                top    + parentInsets.top  - childInsets.top,

                right  + parentInsets.left + childInsets.right,

                bottom + parentInsets.top  + childInsets.bottom);

    }

setOpticalFrame最终也会调用setFrame

protected boolean setFrame(int left, int top, int right, int bottom) {

...

            mTop = top;

            mRight = right;

            mBottom = bottom;

...

}


阅读更多
上一篇android:duplicateParentState
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭