我有 TableLayout,我希望将按钮作为单元格。所有按钮应具有相同的宽度。所有的按钮都应该有相同的高度。 (体重和高度会因我要填满屏幕而不同)。
我确信我做的一切都是正确的,但不幸的是只有宽度是一样的。问题在于高度 - 前两行具有相同的高度,第三行较小(或者更准确地说,只要按钮不包含任何文本,高度就相同,但是当我放置文本时,高度不相等).我简直不敢相信它不起作用,所以我什至做了屏幕截图,并在图形程序中检查了距离。
我的 table :
<TableLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:stretchColumns="*"
android:shrinkColumns="*"
android:weightSum="3"
android:padding="@dimen/dialog_margin"
>
<TableRow
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:stretchColumns="*"
android:gravity="center"
android:weightSum="2">
<Button
android:id="@+id/button_0"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
/>
<Button
android:id="@+id/button_1"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:stretchColumns="*"
android:gravity="center"
android:weightSum="2">
// buttons analogously as in previous row....
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:stretchColumns="*"
android:gravity="center"
android:weightSum="2">
// buttons analogously as in previous row....
</TableRow>
我还尝试将 TableRow
高度设置为 match_parent
。这没有帮助。
顺便说一句,shrinkColums
是如何工作的,特别是与 stretchColumns
一起工作? (我有带和不带 shrinkColumns
的版本,看起来没有区别。
最佳答案
我认为,添加文本时不改变宽度是不可能的。但我认为你可以试试这个。当您添加文本时,请这样写:
setText("<html>your text<html>");
它可能有帮助,但也许文本不会以全尺寸显示
关于java - Android TableLayout - 单元格的等宽和等高 - 不起作用,为什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21801594/