我有表格布局,我想有按钮作为单元格。所有按钮的宽度应相同。所有的按钮都应该有相同的高度。(重量和高度将不同,因为我想填充屏幕)。
我确信我做的一切都是对的,但不幸的是,只有宽度是一样的。问题在于高度-前两行的高度相同,第三行的高度较小(或者更准确地说,只要按钮不包含任何文本,高度就相同,但当我放置文本时,高度就不相等)。我不敢相信它不起作用,所以我做了甚至截图,我检查了距离在图形程序。
我的桌子:
<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>");
也许会有帮助,但也许文字不会是全尺寸的