【发布时间】:2018-09-12 18:12:14
【问题描述】:
我已经成功创建了一个带有 TableRow 和一些 TextViews 的 TableLayout。像这样:
<?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:stretchColumns="1">
<TableRow>
<TextView
android:text="A"
android:padding="3dip" />
<TextView
android:text="B"
android:gravity="right"
android:padding="3dip" />
</TableRow>
</TableLayout>
但是,当我使用带有 Customview 的 TableRow 制作 TableLayout 时,它只显示最后一个 CustomView:
<?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:stretchColumns="1">
<TableRow>
<MyFirstView
android:id="@+id/MyFirstView"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="#fff400" />
<MySecondView
android:id="@+id/MySecondView"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="#0045ff" />
</TableRow>
</TableLayout>
视图在 LinarLayout 中运行良好,是不是缺少一些东西?
【问题讨论】:
-
使
android:stretchColumns="1"等于android:stretchColumns="2"并尝试 -
0 显示第一个,1 显示第二个,2 显示空白屏幕。删除它会显示一个空白屏幕,但将两者都设置为 layoutwidth 100dp 会显示两者。如何将它们设置为 50% 宽度?我希望表格为我格式化
-
我需要了解,你为什么首先使用
。你可以用约束布局做 50% 的事情 -
这个片段展示了如何设置宽度 50% android:layout_width="0dp" android:layout_weight=".50"
标签: android layout android-tablelayout