开发者

How to create 4 buttons in 2rows and 2 columns at center of the screen

开发者 https://www.devze.com 2023-02-20 05:38 出处:网络
<TableLayout xmlns:android=\"http://schemas.android.com/apk/res/android\" android:id=\"@+id/TableLayout01\"
<TableLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/TableLayout01"
    android:layout_height="wrap_content" android:layout_width="fill_parent">
    <TableRow android:id="@+id/TableRow01" android:layout_width="wrap_content"
                    android:layout_height="wrap_content">

        <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:text="Settings"
            android:id="@+id/btnSettings"></Button>
        <Button android:text="@+id/Button01" android:id="@+id/Button01"
            android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>          
    </TableRow>
    <TableRow android:id="@+id/TableRow02" android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <Button android:text="@+id/Button03" android:id="@+id/Button03"
            android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
        <Button android:text="@+id/Button04" android:id="@+id/Button04"
            android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>

    </Tab开发者_开发知识库leRow>
</TableLayout>

please give suggestions,whether the code is right or wrong???


So close!

First you need to put the whole table layout in the following view. This can be your root view if you want

<RelativeLayout android:layout_width="fill_parent" android:id="@+id/relativeLayout1" android:layout_height="fill_parent">

Then just ad to your table layout the following atribute:

android:layout_centerInParent="true"

And finally change in the table layout android:layout_width="fill_parent" to android:layout_width="wrap_content"

Easy!

0

精彩评论

暂无评论...
验证码 换一张
取 消