gpt4 book ai didi

xml - Android XML - 如何使项目最左、居中和最右对齐

转载 作者:太空宇宙 更新时间:2023-11-03 11:41:32 25 4
gpt4 key购买 nike

我有生成一个按钮、一个 TextView 和另一个按钮的 XML 代码,如何让按钮出现在最左边, TextView 出现在中间,最后一个按钮出现在最右边?

<?xml version="1.0" encoding="utf-8"?>  
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">

<Button android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel">
</Button>
<TextView android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Place">
</TextView>
<Button android:id="@+id/Button03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save">
</Button>

</LinearLayout>

最佳答案

我会推荐使用 RelativeLayout,它使事情变得容易得多。

通过使用 RelativeLayout,您可以将 TextView 设置为在父级中水平居中或在父级中居中

这样做之后,您可以通过将这些按钮与父侧对齐或将它们直接附加到 TextView 的两侧,将这些按钮直接附加到远侧,也许添加一点填充,然后你就得到了你的间距。

关于xml - Android XML - 如何使项目最左、居中和最右对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2710666/

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