在不设置绝对宽度的情况下,使子视图比其父视图更宽?

时间:2013-06-02 18:36:53

标签: android layout

如果不使用绝对宽度,如何使子视图比父视图宽?

以下XML导致子视图维度受到父级约束。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="800dp" 
        android:layout_height="800dp"
        android:background="@drawable/red_border" />

</RelativeLayout>

enter image description here

如果我为父布局设置了绝对宽度,那么孩子就不会受到约束。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="800dp"
    android:layout_height="800dp" >

    <LinearLayout
        android:layout_width="800dp" 
        android:layout_height="800dp"
        android:background="@drawable/red_border" />

</RelativeLayout>

enter image description here

0 个答案:

没有答案
相关问题