【发布时间】:2012-07-13 01:58:46
【问题描述】:
我有以下布局:
<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,它将是 40dip。但我需要的正是 fill_parent 属性。
【问题讨论】:
-
你能发一张你想要达到的效果图吗?
-
试试这个,使用 android:layout_alignParentLeft="true" 作为你的视图,然后设置 task_item_startstop_button 相对于它。给一个 id 来查看
-
@AleksG 我需要在此布局的左侧有垂直条
-
@Shubhayu 它没有帮助
-
嘿,我也面临同样的问题,我需要左侧条,但上面的代码我试过它没有任何线索为什么视图不采用 fill_parent 作为高度属性?,如果我将高度硬编码为 10 或20 次浸就可以了。
标签: android android-relativelayout fill-parent