首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TableRow占用太多空间

TableRow占用太多空间
EN

Stack Overflow用户
提问于 2019-07-21 00:33:02
回答 1查看 80关注 0票数 0

我正在尝试使用TableLayout来创建网格,但是rowHeights并没有像我预期的那样分布。我不能使用gridlayout,因为我想让rowheights在以后发生变化。

xml:

代码语言:javascript
复制
<?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"
     android:orientation="vertical">

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="vertical">

        <androidx.cardview.widget.CardView
            android:layout_height="match_parent"
            android:layout_width="0dp"
            android:layout_weight="1">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal">

                <View
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="#f0f"/>

                <View
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="#ff0"/>

            </LinearLayout>
        </androidx.cardview.widget.CardView>
    </TableRow>



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

        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#0ff">
        </TextView>

        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#0f0">
        </TextView>
        </TableRow>


    </TableLayout>

第一行应该只占表格布局高度的一半,但几乎占满了整个屏幕。将cardViews内容替换为:

代码语言:javascript
复制
    <ListView
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:background="#f00"/>

为我提供了预期的间距。我做错了什么?

EN

回答 1

Stack Overflow用户

发布于 2019-07-21 00:49:06

尝试对CardViewLinearLayoutView使用android:layout_height="wrap_content"

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57126635

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档