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

标签 xml android layout alignment

我有生成一个按钮、一个 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/

相关文章:

java - FAIL - 上下文路径/salamander 中的应用程序无法启动

c# - 当字符在 CDATA 中时,为什么 XML 序列化程序会抛出无效字符异常?

Android -- 如何将 View 定位到屏幕外?

html - Bootstrap V2 "boxed"(1170px) 布局中的全宽面板

layout - SwiftUI:相对于中央 View 进行布局

c++ - Xerces DOMNode 将节点名称返回为#Text

xml - 如何不使用Java将xml数据直接加载到Hive Table中而无需将其转换为平面文件

java - 保存截图 cocos2d-x android

java - Android - 如何声明 'this' 的变量?

java - GIF 图像在我的应用程序中不起作用