有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在RelativeLayout中使框架布局底部的按钮居中

这是我的xml代码:

<LinearLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
    安卓:layout_width="match_parent"
    安卓:layout_height="match_parent"
    安卓:orientation="vertical">

    <FrameLayout
        安卓:id="@+id/nero"
        安卓:layout_width="match_parent"
        安卓:layout_height="wrap_content" />

    <RelativeLayout
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:layout_gravity="center"
        安卓:orientation="vertical">

        <Button
            安卓:layout_width="130dp"
            安卓:layout_height="130dp" />

         ....

    </RelativeLayout>

    <FrameLayout
        安卓:id="@+id/imprint"
        安卓:layout_width="match_parent"
        安卓:layout_height="wrap_content"
        安卓:layout_gravity="bottom|center_horizontal">

        <Button
            安卓:layout_width="230dp"
            安卓:layout_height="230dp" />
    </FrameLayout>

</LinearLayout>

我想把FrameLayout放在LinearLayout的底部,FrameLayout中的所有元素都应该居中。我该怎么做


共 (2) 个答案

  1. # 1 楼答案

    框架布局中使用布局

     android:layout_gravity="bottom|center"
    

    同时使用底部边距,使其从底部处于完美位置

    android:layout_marginBottom="20dp"
    
  2. # 2 楼答案

    要将按钮置于FrameLayout的中心,您应该添加:

    android:layout_gravity="center"
    

    Button或:

    android:gravity="center"
    

    FrameLayout的内部。顺便说一句,如果Button是唯一的孩子,你为什么要使用FrameLayout