我正在尝试为ListView中的列表项进行以下布局。理想情况下,我希望布局有5个文本视图,排列如下: 基本上在上排我希望每端的两个TextView是固定宽度,而另外两个同样分割剩余空间。我已经找到了关于如何使一个textview填充剩余空间的建议,但没有关于两个文本视图如何均匀分割空间的建议。生成的五个TextView集应填充布局项
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="6dip">
<TextView
android:id = "@+id/s1"
android:layout_width="50dip"
android:layout_height = "50dip"
android:text="what"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="left"
/>
<TextView
android:id = "@+id/t1"
android:layout_width="fill_parent"
android:layout_height = "50dip"
android:layout_toRightOf="@id/s1"
android:text="why"
android:layout_alignParentTop="true"
/>
<TextView
android:id = "@+id/t2"
android:layout_width="fill_parent"
android:layout_height = "50dip"
android:layout_toRightOf="@id/t1"
android:text="why"
android:layout_alignParentTop="true"
/>
<TextView
android:id = "@+id/s2"
android:layout_width="50dip"
android:layout_height = "50dip"
android:layout_toRightOf="@id/t2"
android:text="what"
android:gravity="right"
android:layout_alignParentTop="true"
/>
<TextView
android:id = "@+id/bottom"
android:layout_width="fill_parent"
android:layout_height = "wrap_content"
android:layout_below="@id/s1"
android:text="what"
android:gravity="center"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
答案 0 :(得分:0)
将父RelativeLayout
替换为LinearLayout
(或者,如果您无法添加其他LinearLayout
并将所有TextViews
添加到其中,请将android:layout_weight="1"
添加到TextViews
所有{{1}}你想占据剩余空间的相等部分。
答案 1 :(得分:0)
试试这个
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="6dip">
<TextView
android:id = "@+id/s1"
android:layout_width="50dip"
android:layout_height = "50dip"
android:text="what"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="left" />
<TextView
android:id = "@+id/s2"
android:layout_width="50dip"
android:layout_height = "50dip"
android:text="what"
android:gravity="right"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"/>
<LinearLayout
android:layout_height="50dip"
android:layout_width="match_parent"
android:layout_toRightOf="@id/s1"
android:layout_toLeftOf="@id/s2"
android:layout_alignParentTop="true"
android:orientation="horizontal" >
<TextView
android:id = "@+id/t1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height = "match_parent"
android:text="why"/>
<TextView
android:id = "@+id/t2"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height = "match_parent"
android:text="why" />
</LinearLayout>
<TextView
android:id = "@+id/bottom"
android:layout_width="fill_parent"
android:layout_height = "wrap_content"
android:layout_below="@id/s1"
android:text="what"
android:gravity="center"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" />
</RelativeLayout>