Android Studio 使用权重计算表行的Android高度

brvekthn  于 2022-11-16  发布在  Android
关注(0)|答案(1)|浏览(138)

创建一个4行的表格,其中3行高度相等,1行高度只有1/2。
我想我应该可以这样做使用这样的代码:

<TableLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:weightSum="3.5">
        <TableRow
            android:layout_height="0dp"
            android:layout_weight="1" >
            <View
                android:background="@color/dark_grey"
                android:layout_height="match_parent"
                android:layout_width="400dp">
            </View>
        </TableRow>
        <TableRow
            android:layout_height="0dp"
            android:layout_weight="1" >
            <View
                android:background="@color/orange"
                android:layout_height="match_parent"
                android:layout_width="400dp">
            </View>
        </TableRow>
        <TableRow
            android:layout_height="0dp"
            android:layout_weight="0.5" >
            <View
                android:background="@color/purple_200"
                android:layout_height="match_parent"
                android:layout_width="400dp">
            </View>
        </TableRow>
        <TableRow
            android:layout_height="0dp"
            android:layout_weight="1" >
            <View
                android:background="@color/dark_grey"
                android:layout_height="match_parent"
                android:layout_width="400dp">
            </View>
        </TableRow>
    </TableLayout>

然而,权重为0.5的行远大于其他3行。

有没有人能告诉我我做错了什么?我想我在这里做错了什么...
谢谢你Celdrion

nbnkbykc

nbnkbykc1#

只需从表行中删除高度字段并添加android:layout_width=“match_parent”
如果你遇到任何其他问题,请告诉我。谢谢

相关问题