我创建了一个TableLayout
两行,其中第一行有一个TextView
行和第二行有两列,第一个有一个ListView
,第二个有一个EditText
和一个Button
每个不同行。 我想高度相等(屏幕正好一半)和两个第二排的列的两行应该是平等的宽度(屏幕恰好一半)。 我想建立这样的事情:
我应该怎么做? 其布局我应该选择?
我创建了一个TableLayout
两行,其中第一行有一个TextView
行和第二行有两列,第一个有一个ListView
,第二个有一个EditText
和一个Button
每个不同行。 我想高度相等(屏幕正好一半)和两个第二排的列的两行应该是平等的宽度(屏幕恰好一半)。 我想建立这样的事情:
我应该怎么做? 其布局我应该选择?
我不认为你目前的解决方案就可以了(因为平等的空间(宽度和高度)+的要求ListView
存在)。 一种解决方案是使用嵌套weights
(这是不好的表现,但(可能是,不知道你做了什么),将打破你的应用程序不是那么重要),如在下面的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<include
android:layout_width="fill_parent"
android:layout_height="wrap_content"
layout="@layout/identical_layout" />
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="TextView" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<ListView
android:id="@+id/list"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1" >
</ListView>
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="ddd" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
避免嵌套在另一个选项weights
的问题是使用RelativeLayout
像下面(I没有测试它):
<?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="fill_parent" >
<include
android:id="@+id/included_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
layout="@layout/identical_layout" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/included_layout" >
<View
android:id="@+id/anchor"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_centerVertical="true" />
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_above="@id/anchor"
android:layout_alignParentTop="true"
android:background="#99cc00"
android:text="TextView" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_alignParentBottom="true"
android:layout_below="@id/anchor" >
<ListView
android:id="@+id/list"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1" >
</ListView>
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="ddd" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
该identical_layout
布局文件代表了您的共享公共布局Activities
。