Подтвердить что ты не робот

Android TableRow растягивается вертикально, чтобы заполнить экран

Я пытаюсь создать вид телефонного набора, используя TableLayout, чтобы создать 12 кнопок в сетке 3x4. Я бы хотел, чтобы строки растягивались вертикально, чтобы использовать все доступное пространство одинаково, но, похоже, fill_parent не работает в TableRows.

Я бы не хотел использовать setMinimumHeight - есть ли способ сделать это правильно в макете?

Большое спасибо,

Ed

4b9b3361

Ответ 1

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TableLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="*"
    >
    <TableRow 
        android:layout_weight="1"
        android:gravity="center">
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
    </TableRow>
    <TableRow 
        android:layout_weight="1"
        android:gravity="center">
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
    </TableRow>
    <TableRow 
        android:layout_weight="1"
        android:gravity="center">
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
    </TableRow>
    <TableRow 
        android:layout_weight="1"
        android:gravity="center">
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
    </TableRow>
</TableLayout>
</LinearLayout>

enter image description here