2

Androidアプリケーションのアイコンベースのメインメニューに取り組んでいます(添付の画像-Google+を参照)。このための明らかなレイアウトはTableLayoutです。

Google+Androidアプリ

しかし、私にはわからず、テーブル自体とその中のアイコンを中央に配置する方法についての情報を見つけることができませんでした。私が思いついたコードは次のとおりです(結果の画像はコードの下にあります):

<TableLayout android:layout_width="fill_parent" android:id="@+id/tableLayout1" android:layout_height="fill_parent" android:stretchColumns="1" android:padding="20dp">
    <TableRow android:id="@+id/tableRow1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="20dp"  >
        <Button android:text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"></Button>
        <Button android:text="Button" android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"></Button>
    </TableRow>
    <TableRow android:id="@+id/tableRow2" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="20dp" >
        <Button android:text="Button" android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" ></Button>
        <Button android:text="Button" android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"></Button>
    </TableRow>
</TableLayout>

TableLayout

ヒントやアイデアをいただければ幸いです。

4

2 に答える 2

2

必要なプログラムのメイン メニューを作成しました。密度に依存しませんが、どこでも使用できることを確認するためにスクロールビューに配置しました。必要に応じてボタンをイメージボタンに変更できるため、必要なメニューが得られます。

コードの簡単な説明:

  • すべての行には、プレースホルダーとして左右にテキストビューがあります。tablelayout'a android:stretchColumns="0,3" は、ボタンの横のスペースを埋めるためにテキストビューを引き伸ばします。
  • マージンを変更して、ボタンを互いに近づけたり離したりできます。

そして今ここにxmlがあります:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TableLayout android:layout_gravity="center" 
        android:layout_width="match_parent" android:layout_height="match_parent"
        android:stretchColumns="0,3">
        <TableRow android:layout_gravity="center">
            <TextView />
            <Button android:text="1" android:layout_margin="15dp"
                android:layout_gravity="center_vertical"
                android:width="100dip" android:height="100dip" />
            <Button android:layout_gravity="center_vertical" 
                android:text="2" android:layout_margin="15dp"
                android:width="100dip" android:height="100dip" />
            <TextView />
        </TableRow>

        <TableRow android:layout_gravity="center">
            <TextView />
            <Button android:text="3"  android:layout_margin="15dp"
                android:layout_gravity="center_vertical"
                android:width="100dip" android:height="100dip" />
            <Button android:text="4"  android:layout_margin="15dp"
                android:layout_gravity="center_vertical"
                android:width="100dip" android:height="100dip" />
            <TextView />
        </TableRow>

        <TableRow android:layout_gravity="center">
            <TextView />
                <Button android:text="5"  android:layout_margin="15dp"
                android:layout_gravity="center_vertical"
                android:width="100dip" android:height="100dip" />
            <Button android:text="6"  android:layout_margin="15dp"
                android:layout_gravity="center_vertical"
                android:width="100dip" android:height="100dip" />
            <TextView />
        </TableRow>
    </TableLayout>
</ScrollView>

そして、これはどのように見えるかです: http://db.tt/yQ5NFhmk

于 2012-01-15T11:55:03.203 に答える
0

スペックで試しandroid:gravity="center"てみてください。TableLayoutこれにより、表の行が画面の中央に配置されます。

また、表の行の中央にボタンを配置するための を追加android:gravity="center"してみてください。TableRow

于 2011-10-16T23:48:49.220 に答える