abidkhan303 abidkhan303 - 24 days ago 7
Android Question

Can not adjust buttons in Tablet Layout in Android

I have tablet layout with displays buttons in 3 rows

<?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" >

<TableLayout
android:id="@+id/TableLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:stretchColumns="*" >

<TableRow
android:id="@+id/TableRow01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:text="Download1"
android:textColor="#EDFF99"
android:textStyle="bold" />

<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:text="Download2"
android:textColor="#EDFF99"
android:textStyle="bold" />
</TableRow>

<TableRow
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="1" >

<Button
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="1"
android:text="Upload1"
android:textColor="#EDFF99"
android:textStyle="bold" />

<Button
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="1"
android:text="Upload2"
android:textColor="#EDFF99"
android:textStyle="bold" />
</TableRow>
<TableRow
android:id="@+id/TableRow01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:text="Download1"
android:textColor="#EDFF99"
android:textStyle="bold" />

<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:text="Download2"
android:textColor="#EDFF99"
android:textStyle="bold" />
</TableRow>
</TableLayout>

</RelativeLayou


t>

and its output is like Figure 1. But i want that row number 2 can cover rest of the area and view (Button) display in center of the screen Like Fig 2.enter image description here

Answer

This code gives you the desired look. Please, try everything before you post on stackoverflow. This was actually very simple. Here's the screenshot:

<TableLayout
    android:id="@+id/TableLayout01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_centerInParent="true"
    android:stretchColumns="*" >

    <TableRow
        android:id="@+id/TableRow01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:layout_weight="1"
            android:text="Download1"
            android:textColor="#EDFF99"
            android:textStyle="bold" />

        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:layout_weight="1"
            android:text="Download2"
            android:textColor="#EDFF99"
            android:textStyle="bold" />
    </TableRow>

    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_weight="1" >

        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_margin="5dp"
            android:layout_weight="1"
            android:text="Upload1"
            android:textColor="#EDFF99"
            android:textStyle="bold" />
    </TableRow>
            <TableRow
        android:id="@+id/TableRow01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:layout_weight="1"
            android:text="Download1"
            android:textColor="#EDFF99"
            android:textStyle="bold" />

        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:layout_weight="1"
            android:text="Download2"
            android:textColor="#EDFF99"
            android:textStyle="bold" />
    </TableRow>
</TableLayout>