RelativeLayout中的layout_height ="fill_parent"不起作用

Dmi*_*riy 5 android relativelayout fill-parent

我有以下布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/item_background"
    android:layout_margin="10dip"
    android:gravity="center_vertical">

    <View
        android:layout_width="30dip"
        android:layout_height="fill_parent"
        android:background="@color/test_color"/>

    <ImageView
        android:id="@+id/task_item_startstop_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/start_task"
        android:layout_centerVertical="true"
        android:focusable="false"
        android:background="#0000"/>

    <View
        android:id="@+id/task_item_line"
        android:layout_width="2dp"
        android:layout_height="40dip"
        android:layout_margin="5dip"
        android:background="@color/line_color"
        android:layout_toRightOf="@id/task_item_startstop_button"/>

    <TextView
        android:id="@+id/task_item_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@android:color/black"
        android:textSize="22sp"
        android:textStyle="bold"
        android:layout_toRightOf="@id/task_item_line" />

    <TextView
        android:id="@+id/task_item_status"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/task_item_suspended"
        android:textSize="18sp"
        android:textColor="@android:color/black"
        android:layout_toRightOf="@id/task_item_line"
        android:layout_below="@id/task_item_title"/>

    <TextView
        android:id="@+id/task_item_timer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dip"
        android:textSize="18sp"
        android:textColor="@android:color/black"
        android:layout_toRightOf="@id/task_item_status"
        android:layout_below="@id/task_item_title"/>

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

我希望在布局的左侧有垂直线(根布局内的第一个视图),其固定宽度和高度等于父级的高度.但是,如果我设置layout_height ="fill_parent"它没有帮助.高度为0.如果我设置高度例如40dip,它将是40倾角.但我需要fill_parent属性.

Jon*_*Jon 0

这能解决您的问题吗?只需将相关元素替换为您自己的即可

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

        <Button 
            android:layout_height="match_parent"
            android:layout_width="30dp"
            android:id="@+id/thebutton"
            android:text="hello world"
            />

    <AnalogClock
        android:id="@+id/analogClock1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/thebutton" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)