LinearLayout at the top and at the bottom of the screen
I have two different LinearLayouts
inside one LinearLayout
and I would like the first layout to be at the top and the second layout to be at the bottom. I tried with android:gravity="top"
but it didn't work. Here is my xml code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:gravity="center">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:gravity="top">
<ImageView android:layout_height="wrap_content" android:id="@+id/imageView1"
android:src="@drawable/icon" android:layout_width="wrap_content"></ImageView>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<TableRow android:weightSum="2">
<Button android:text="Button" android:id="@+id/button2"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1"></Button>
<Button android:text="Button" android:id="@+id/button1"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1"></Button>
</TableRow>
<TableRow android:weightSum="2">
<Button android:text="Button" android:id="@+id/button3"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1"></Button>
<Button android:text="Button" android:id="@+id/button4"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1"></Button>
</TableRow>
</TableLayout>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:gravity="bottom">
<ImageView android:layout_height="wrap_content" android:id="@+id/imageView1"
android:src="@drawable/icon" android:layout_width="wrap_content"></ImageView>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<TableRow android:weightSum="2">
<Button android:text="Button" android:id="@+id/button2"
android:layout_width="wrap_content" andr开发者_高级运维oid:layout_height="wrap_content"
android:layout_weight="1"></Button>
<Button android:text="Button" android:id="@+id/button1"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1"></Button>
</TableRow>
<TableRow android:weightSum="2">
<Button android:text="Button" android:id="@+id/button3"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1"></Button>
<Button android:text="Button" android:id="@+id/button4"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1"></Button>
</TableRow>
</TableLayout>
</LinearLayout>
You could simply add :
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1" />
between your top and bottom LinearLayout
(and remove the gravity from the parent container).
change you parent layout as RelativeLayout
instead of LinearLayout
, and
for top of the parent layout set following in child layout
android:layout_alignParentTop="true"
and for bottom of the parent layout set following in child layout
android:layout_alignParentBottom="true"
精彩评论