关闭

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

147人阅读 评论(0) 收藏 举报

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;

...

}


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:333次
    • 积分:22
    • 等级:
    • 排名:千里之外
    • 原创:2篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章存档