Android TableLayout的行为与表不同
给定此布局XML片段:Android TableLayout的行为与表不同,android,Android,给定此布局XML片段: <TableLayout android:id="@+id/review_ltpv_table" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:stretchColumns="*"> <
<TableLayout
android:id="@+id/review_ltpv_table"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:stretchColumns="*">
<!-- TODO: This row's cells don't line up with the rows below. Fix. -->
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/review_text_view_look"
android:text="@string/review_look"
android:textAppearance="@style/TextBody" />
<TextView
android:id="@+id/review_text_view_taste"
android:text="@string/review_taste"
android:textAppearance="@style/TextBody" />
<TextView
android:id="@+id/review_text_view_portion"
android:text="@string/review_portion"
android:textAppearance="@style/TextBody" />
<TextView
android:id="@+id/review_text_view_value"
android:text="@string/review_value"
android:textAppearance="@style/TextBody" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="0dp" >
<ToggleButton
android:id="@+id/review_look_positive"
style="@style/ButtonPositive"
android:onClick="onLookPositive"
android:textOn="@null"
android:textOff="@null" />
<ToggleButton
android:id="@+id/review_taste_positive"
style="@style/ButtonPositive"
android:onClick="onTastePositive"
android:textOn="@null"
android:textOff="@null" />
<ToggleButton
android:id="@+id/review_portion_positive"
style="@style/ButtonPositive"
android:onClick="onPortionPositive"
android:textOn="@null"
android:textOff="@null" />
<ToggleButton
android:id="@+id/review_value_positive"
style="@style/ButtonPositive"
android:onClick="onValuePositive"
android:textOn="@null"
android:textOff="@null" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="0dp" >
<ToggleButton
android:id="@+id/review_look_negative"
style="@style/ButtonNegative"
android:onClick="onLookNegative"
android:textOn="@null"
android:textOff="@null" />
<ToggleButton
android:id="@+id/review_taste_negative"
style="@style/ButtonNegative"
android:onClick="onTasteNegative"
android:textOn="@null"
android:textOff="@null" />
<ToggleButton
android:id="@+id/review_portion_negative"
style="@style/ButtonNegative"
android:onClick="onPortionNegative"
android:textOn="@null"
android:textOff="@null" />
<ToggleButton
android:id="@+id/review_value_negative"
style="@style/ButtonNegative"
android:onClick="onValueNegative"
android:textOn="@null"
android:textOff="@null" />
</TableRow>
</TableLayout>
我看到:
为什么上排单元格之间的垂直边界与下排单元格之间的垂直边界不对齐?这不是一张桌子
如果我从布局标签中删除android:stretchColumns=“*”,它看起来更糟-最上面一行的单元格就在左边聚集
如果我在文本视图中添加android:layout\u weight=“1”
,则没有什么区别
这是API级别22。我认为您没有正确使用“重量”,我建议您尝试将第一行更改为:
<TableRow
android:weightSum="4">
<TextView
android:id="@+id/review_text_view_look"
android:text="@string/review_look"
android:layout_weight="1"
android:textAppearance="@style/TextBody" />
<TextView
android:id="@+id/review_text_view_taste"
android:text="@string/review_taste"
android:layout_weight="1"
android:textAppearance="@style/TextBody" />
<TextView
android:id="@+id/review_text_view_portion"
android:text="@string/review_portion"
android:layout_weight="1"
android:textAppearance="@style/TextBody" />
<TextView
android:id="@+id/review_text_view_value"
android:text="@string/review_value"
android:layout_weight="1"
android:textAppearance="@style/TextBody" />
</TableRow>
所以每个单元格都有相同的重量和大小对不起,这没有什么区别。如果这样做有效,它也会引发一个问题:如果需要告知所有这些权重,那么表格布局的意义何在?尝试从每个表格行中删除所有的布局宽度和布局高度,我认为这些属性会改变表格布局行为不走运,对不起。您尝试过这样做吗:是的,没有区别。