【发布时间】:2019-07-20 16:33:01
【问题描述】:
我正在尝试使用 TableLayout 来制作网格,但 rowHeights 没有按我预期的那样分布。我不能使用 gridlayout,因为我希望稍后改变行高。
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"/>
给了我预期的间距。我做错了什么?
【问题讨论】:
标签: android android-layout android-tablelayout