android - 在表格内垂直对齐表格行以覆盖整个区域

标签 android android-tablelayout

我有一个覆盖整个屏幕并包含可变行数的表格。

我想知道如何垂直均匀分布这些行,以便它们占据整个表的空间。

我尝试过layout_weight和weightSum,但它不起作用。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout01"
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="0,1,2"
        android:id="@+id/maintable"
        android:weightSum="3" >

        <TableRow 
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:layout_weight="1" >
            <TextView
                android:text="text 1_1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                />

            <TextView
                android:text="text 2_1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                />

            <TextView
                android:text="text 3_1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                />
        </TableRow>

        <TableRow 
            android:layout_width="fill_parent"
            android:layout_height="1dp" 
            android:layout_weight="1" >
            <TextView
                android:text="text 1_2"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                />

            <TextView
                android:text="text 2_2"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                />

            <TextView
                android:text="text 3_2"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                />
        </TableRow>

        <TableRow 
            android:layout_width="fill_parent"
            android:layout_height="1dp" 
            android:layout_weight="1" >
            <TextView
                android:text="text 1_3"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                />

            <TextView
                android:text="text 2_3"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                />

            <TextView
                android:text="text 3_3"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                />
        </TableRow>

    </TableLayout>
</LinearLayout>

最佳答案

您的代码看起来错误,因为您没有为垂直设置“填充父级”约束 轴

    <TableRow 
        android:layout_width="fill_parent"
        android:layout_height="1dp" 
        android:layout_weight="1" >

应该是

    <TableRow 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:layout_weight="1" >

关于android - 在表格内垂直对齐表格行以覆盖整个区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9324658/

相关文章:

android - 使用webview崩溃播放Youtube

android - 从android中的表格布局中动态删除行

android - 使用 android Studio 的带有 TextView 和 EditText 的 TableLayout

android - 具有相应标签的 radio 组的 TableLayout 在 android 中对齐

java - 使用底部导航栏

c# - OnDisappearing 和 OnAppearing 覆盖不能被视为页面导航的保证指示? Xamarin.Forms

android - 如何避免 TextView 中文本的字符换行,以自动调整文本大小?

java - 有人可以解释为什么该行没有在此 TableLayout 中换行文本吗?

android - 带有图像和 2 TextView 的 TableRow

android - sqlite 舍入 'error'