相对布局中的TextView不会展开以填充可用空间

时间:2014-09-28 19:42:43

标签: android android-layout

为什么以下布局中的灰色框(transaction_amount)不会扩展到可用的完整空间,即使layout:height与它的父级匹配。

enter image description here

<TextView android:id="@+id/transaction_amount"
    android:layout_width="120dp"
    android:layout_height="match_parent"
    android:textAppearance="@android:style/TextAppearance.DeviceDefault.Large"
    android:textColor="@android:color/primary_text_light"
    android:background="@drawable/rounded_rectangle"
    tools:text="100"/>

<TextView
    android:id="@+id/transaction_name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/transaction_amount"
    android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium"
    android:textColor="@android:color/secondary_text_light"
    tools:text="Mast Kalandar Dinner"/>

<TextView
    android:id="@+id/shared_bw_label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignStart="@id/transaction_name"
    android:layout_toRightOf="@+id/transaction_amount"
    android:layout_below="@id/transaction_name"
    android:textAppearance="@android:style/TextAppearance.DeviceDefault.Small"
    android:textColor="@android:color/secondary_text_light_nodisable"
    android:text="Shared Between"/>

<TextView
    android:id="@+id/shared_bw_csv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@id/shared_bw_label"
    android:layout_alignBaseline="@id/shared_bw_label"
    android:textAppearance="@android:style/TextAppearance.DeviceDefault.Small"
    android:textColor="@android:color/secondary_text_light_nodisable"
    tools:text="Ashu, Amol"/>

1 个答案:

答案 0 :(得分:0)

请尝试使用此layout,我相信它会对您有所帮助。

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="120dp"
        android:layout_height="match_parent"
        android:layout_marginRight="10dp"
        android:background="#ffa"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="100"
            android:textAppearance="?android:attr/textAppearanceSmall" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Small Text"
            android:textAppearance="?android:attr/textAppearanceSmall" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Small Text"
            android:textAppearance="?android:attr/textAppearanceSmall" />
    </LinearLayout>
</LinearLayout>