I have created a TableLayout
with two rows where first row has one TextView
and second row has two columns, first one has a ListView
and the second one has one EditText
and a Button
each in different rows. I want both rows of equal height (exactly half of the screen) and both of the columns of second row should be of equal width (exactly half of the screen). I Want to build something like this:
我应该如何进行?我应该选择哪种布局?
我认为您当前的解决方案不起作用(因为需要相等的空间(宽度和高度)+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
如下(我没有测试过):
<?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>
The identical_layout
布局文件代表您共享的通用布局Activities
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)