1

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

以下 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>

在此处输入图像描述

如果我为父布局设置绝对宽度,则子布局不会受到约束。

<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>

在此处输入图像描述

4

0 回答 0