I wrote this XML code;
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="20"
>
<TableRow
android:layout_height="fill_parent"
android:layout_weight="10"
android:layout_w开发者_JAVA技巧idth="fill_parent">`enter code here`</TableRow>
<TableRow
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="9">
<Gallery
android:layout_height="fill_parent"
android:id="@+id/gallery"
android:layout_width="fill_parent"
android:layout_weight="1">
</Gallery>
</TableRow>
<TableRow
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
>
<Button
android:id="@+id/Button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
>
</Button>
<Button
android:id="@+id/Button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1">
</Button>
<Button
android:id="@+id/Button3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1">
</Button>
<Button
android:id="@+id/Button4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1">
</Button>
</TableRow>
This code is shown like I want however when I run the code buttons size are changing with images size in gallery.How can I write the XML code independent from each other(gallery and buttons). Thanks for Help
I would recommend that you use 2 LinearLayouts, A vertical LinearLayout to hold the Gallery and a horizontal LinearLayout, which in turn contains the various buttons.
Code:
<?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">
<Gallery
android:layout_height="fill_parent"
android:id="@+id/gallery"
android:layout_width="fill_parent"
android:layout_weight="1">
</Gallery>
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content">
<Button
android:id="@+id/Button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1">
</Button>
<Button
android:id="@+id/Button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1">
</Button>
<Button
android:id="@+id/Button3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1">
</Button>
<Button
android:id="@+id/Button4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1">
</Button>
</LinearLayout>
</LinearLayout>
精彩评论