gpt4 book ai didi

android - XML 表布局?两个等宽的行填充了等宽的按钮?

转载 作者:IT王子 更新时间:2023-10-29 00:10:40 33 4
gpt4 key购买 nike

这是我的 LAND 格式 XML 的一部分:

<TableLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:stretchColumns="*">
<TableRow>
<Button
android:id="@+id/countbutton"
android:text="@string/plus1"/>
<Button
android:id="@+id/resetbutton"
android:text="@string/reset"
/>
</TableRow>
</TableLayout>

现在我没有得到 - 一行和按钮的宽度取决于按钮内的 TEXT。如果两个文本都一样长,可以说: TEXT 没问题 - 表的一半在屏幕中间。但如果它们的大小不同 - 让我们说“A”和“这是长按钮”,表格的中心不再位于屏幕中间,因此按钮的宽度不相等......

最佳答案

要在按钮大小相同的行中设置按钮。

    <LinearLayout android:orientation="horizontal" 
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_width="0dip"/>
<Button android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_width="0dip"/>
</LinearLayout>

并为您的按钮填写其他 xml 属性。

神奇之处在于 layout_weight 和 width 属性。您不需要表格布局。这些属性告诉布局你的 View 应该在父布局中占据相等的空间。

关于android - XML 表布局?两个等宽的行填充了等宽的按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2865497/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com