5

我有以下布局:

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

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

4

2 回答 2

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>
于 2013-12-31T13:20:14.987 回答
-1

您已经为 Parent 相对布局提供了边距,这就是为什么每当您添加任何内容时,它总是为您的小部件提供边距。从您的父级相对布局中删除 android:layout_margin="10dip" 然后您会得到 fil 父级中的行。

于 2014-01-23T07:53:44.790 回答