Android TableRow 垂直拉伸(stretch)以填满屏幕

标签 android

我正在尝试创建一个电话拨号器 View ,使用 TableLayout 在 3x4 网格中创建 12 个按钮。我希望行垂直拉伸(stretch)以平均使用所有可用空间,但似乎 fill_parent 不适用于 TableRows。

我不想使用 setMinimumHeight - 有没有办法在布局中正确执行此操作?

非常感谢,

埃德

最佳答案

<?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

关于Android TableRow 垂直拉伸(stretch)以填满屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5538366/

相关文章:

android - 旋转后的TextView : are these problems bugs?

Android CollapsingToolbarLayout 与自定义 View

android - 使用 Netbeans 或 Visual Studio 设置 Android SDK?

java - 没有名字的静态方法

Android - 生命周期和保存实例状态问题

java - 当viewpager重新启动时,它会继续执行之前的fragment

java - 如何在 Android 中全局保存 "list"或至少实例以供在任何 Activity 中使用?

android - android中的未接来电检测

Android 表情符号支持库无法在所有设备上呈现表情符号

android - Firebase 通知 - 无效的注册 token ,请检查 Android 中的 token 格式