一行中有三个视图 - 中间线填补了空白

时间:2013-07-22 16:25:49

标签: android relativelayout

我有3个观点,我希望在一行中。这些视图是:TextView View TextView,应该如下所示:

Today --------- 89

行应该填充此2 TextViews留下的所有空闲空间。 我尝试使用此代码,但是将“89”放在屏幕外。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<TextView
    android:id="@+id/list_mail_header_day"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Today"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="@color/background_seen" />

<View
    android:id="@+id/list_mail_header_line"
    android:layout_width="wrap_content"
    android:layout_height="2dp"
    android:layout_alignParentTop="true"
    android:layout_margin="2dp"
    android:layout_toRightOf="@+id/list_mail_header_day"
    android:background="@color/background_seen" />

<TextView
    android:id="@+id/list_mail_header_counter"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/list_mail_header_line"
    android:text="89"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:textColor="#000"
    android:textStyle="bold" />

1 个答案:

答案 0 :(得分:1)

尝试将LinearLayout与非零布局权重相结合:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/list_mail_header_day"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Today"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="@color/background_seen" />

    <View
        android:id="@+id/list_mail_header_line"
        android:layout_width="0dp"
        android:layout_height="2dp"
        android:layout_weight="1"
        android:layout_margin="2dp"
        android:background="@color/background_seen" />

    <TextView
        android:id="@+id/list_mail_header_counter"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="89"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="#000"
        android:textStyle="bold" />

</LinearLayout>