按钮填充TableLayout中的整行?

Caf*_*tte 3 android android-layout android-tablelayout

我有一个LinearLayout垂直方向,在第一行我添加了一个填充父母的按钮.

我想使用TableLayout实现相同的功能.
到目前为止我尝试过的是:

在此输入图像描述

<TableLayout 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/tableLayout">
<TableRow 
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:id="@+id/firstRow">

<Button
     android:id="@+id/button1"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:text="Button" />
</TableRow >
</TableLayout>
Run Code Online (Sandbox Code Playgroud)

TableRow填充母,但是行内的按钮将不会填充整个行.

如何使按钮像这样填充父母?


编辑:

以及如何使它垂直填充父母像这样:

在此输入图像描述

Mat*_*lár 5

使用 android:layout_weight="1"

   <?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TableRow>

        <Button
            android:layout_width="0dip"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="Why is doing layouts on Android" />
    </TableRow>

    <TableRow>

        <Button
            android:layout_width="0dip"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="damn" />
    </TableRow>

</TableLayout>
Run Code Online (Sandbox Code Playgroud)

好像 :

在此输入图像描述

  • 是的,使用权重来解决问题。+1 (2认同)