如何在Android中制作网格状布局

如何在Android中制作网格状布局,android,Android,我正在尝试制作一个在水平线上有三个按钮(每个按钮的宽度相同)的布局 xxxx xxxx xxxx xxxx xxxx xxxx X代表按钮。如何将33%分配给每个单元格,然后在单元格内添加一个不拉伸的按钮?您应该能够使用:3列,2行,stretchMode为spacingWidthUniform 编辑:还没有尝试过,但这应该是有效的 <TableLayout android:id="@+id/TableLayout01" android:layout_he

我正在尝试制作一个在水平线上有三个按钮(每个按钮的宽度相同)的布局

xxxx   xxxx   xxxx
xxxx   xxxx   xxxx

X代表按钮。如何将33%分配给每个单元格,然后在单元格内添加一个不拉伸的按钮?

您应该能够使用:3列,2行,stretchMode为
spacingWidthUniform

编辑:还没有尝试过,但这应该是有效的

<TableLayout android:id="@+id/TableLayout01"
        android:layout_height="wrap_content" android:layout_width="fill_parent" android:stretchMode="spacingWidthUniform">
        <TableRow android:id="@+id/TableRow01" android:layout_width="fill_parent"
            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>
            <Button android:text="@+id/Button02" android:id="@+id/Button02"
                android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
        </TableRow>
        <TableRow android:id="@+id/TableRow02" android:layout_width="fill_parent"
            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>
            <Button android:text="@+id/Button05" android:id="@+id/Button05"
                android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
        </TableRow>
    </TableLayout>

您应该能够使用:3列,2行,一个
间隔widthuniform
的stretchMode

编辑:还没有尝试过,但这应该是有效的

<TableLayout android:id="@+id/TableLayout01"
        android:layout_height="wrap_content" android:layout_width="fill_parent" android:stretchMode="spacingWidthUniform">
        <TableRow android:id="@+id/TableRow01" android:layout_width="fill_parent"
            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>
            <Button android:text="@+id/Button02" android:id="@+id/Button02"
                android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
        </TableRow>
        <TableRow android:id="@+id/TableRow02" android:layout_width="fill_parent"
            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>
            <Button android:text="@+id/Button05" android:id="@+id/Button05"
                android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
        </TableRow>
    </TableLayout>

一种方法是使用android:layout\u weight=“1”:


一种方法是使用android:layout\u weight=“1”: