I do not think your current solution will work (due to the requirement for equal space (width and height) + the presence of a ListView ). One solution is to use nested weights (which are bad for performance, but (perhaps not knowing what you are doing) is not something important that will break your application), as in the layout below:
<?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>
Another way to avoid the weights nested problem is to use a RelativeLayout as shown below (I haven't tested it):
<?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 layout file represents a common layout common to your Activities .
Luksprog May 28 '12 at 8:14 2012-05-28 08:14
source share