我正在尝试使用TableLayout来创建网格,但是rowHeights并没有像我预期的那样分布。我不能使用gridlayout,因为我想让rowheights在以后发生变化。
xml:
<?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内容替换为:
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f00"/>为我提供了预期的间距。我做错了什么?
发布于 2019-07-21 00:49:06
尝试对CardView、LinearLayout和View使用android:layout_height="wrap_content"。
https://stackoverflow.com/questions/57126635
复制相似问题