Android layout 为什么设置为同一列的TableLayout组件不对齐?
我很确定我遗漏了一些关于TableLayout的基本信息,但在做了一些搜索和阅读之后,我无法找出它。 代码如下:Android layout 为什么设置为同一列的TableLayout组件不对齐?,android-layout,android-tablelayout,Android Layout,Android Tablelayout,我很确定我遗漏了一些关于TableLayout的基本信息,但在做了一些搜索和阅读之后,我无法找出它。 代码如下: <TableLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <TableRow> <Button android:layout_column="0" android:text="00" android:
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableRow>
<Button android:layout_column="0" android:text="00" android:visibility="gone"/>
<Button android:layout_column="1" android:text="01"/>
</TableRow>
<TableRow>
<Button android:layout_column="0" android:text="10"/>
<Button android:layout_column="1" android:text="11"/>
</TableRow>
</TableLayout>
结果如下:
我希望按钮“01”与按钮“11”对齐,因为它们都设置为第1列。有人能指出我误解了什么吗
[编辑]
如果“00”的可见性值“gone”是一个问题,为什么删除它会使其工作如下:
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableRow>
<Button
android:layout_column="1"
android:text="01" />
</TableRow>
<TableRow>
<Button
android:layout_column="0"
android:text="10" />
<Button
android:layout_column="1"
android:text="11" />
</TableRow>
</TableLayout>
结果:
这是因为您将按钮的可见性设置为值为00,这就是它在布局中不占空间的原因 在这里你可以找到两者的用法
View.GONE
此视图不可见,并且不占用任何空间用于布局
视图。不可见
此视图不可见,但仍会占用空间用于布局
因此,只需将值为00的按钮的可见性更改为不可见,即可按预期工作
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableRow>
<Button
android:layout_column="0"
android:text="00"
android:visibility="invisible" />
<Button
android:layout_column="1"
android:text="01" />
</TableRow>
<TableRow>
<Button
android:layout_column="0"
android:text="10" />
<Button
android:layout_column="1"
android:text="11" />
</TableRow>
</TableLayout>
希望这能对您有所帮助。谢谢您的帮助。为了回应你的回答,我编辑了我的问题,因为在评论中无法显示代码和图像。我的主要观点是android:layout_列在任何情况下都不能正常工作。