184_wrap和match的发现

来源:互联网 发布:网络大电影投资模式 编辑:程序博客网 时间:2024/05/03 14:39

wrapmatch的发现

发现一个现象,算是给了我一点教训

但是也是非常合理的

 

是这样的

 

我们在一个LinearLayout里面放一个TextView

    <LinearLayout

        android:layout_width="wrap_content"

        android:orientation="vertical"

        android:layout_height="wrap_content">

 

        <TextView

            android:layout_width="match_parent"

            android:text="text"

            android:background="#ff0000"

            android:layout_height="wrap_content"/>

 

    </LinearLayout>

 

 

我们给外面是wrap,给里面是match

我们发现效果是TextView是小的,也就是wrap

 

另外

如果是horizontal的话,也是wrap

 

 

 

 

然后我们在一个RelativeLayout里面放一个TextView

 

        <RelativeLayout

            android:layout_width="wrap_content"

            android:layout_height="wrap_content">

 

            <TextView

                android:layout_width="match_parent"

                android:text="text"

                android:background="#00ff00"

                android:layout_height="wrap_content"/>

 

        </RelativeLayout>

 

 

我们发现这里TextViewmatch

 

 

 

 

为什么LinearLayoutRelativeLayout是不同的

 

我们来看看两个layout的源码

看看他们是怎么测绘的

 

 

我们先看看两个layoutonMeasure方法

 

非常抱歉

我发现RelativeLayoutonMeasure300

LinearLayout更是分了2

        if (mOrientation == VERTICAL) {

            measureVertical(widthMeasureSpec, heightMeasureSpec);

        } else {

            measureHorizontal(widthMeasureSpec, heightMeasureSpec);

        }

measureVertical300

measureHorizontal400

 

看了很久没有看到关键性的影响子控件的代码

 

等我有空的时候再看吧

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0 0
原创粉丝点击