繁体   English   中英

如何在RelativeLayout中的FrameLayout底部将按钮居中

[英]How to center a button at the bottom of a FrameLayout in a RelativeLayout

这是我的xml代码:

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

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

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

        <Button
            android:layout_width="130dp"
            android:layout_height="130dp" />

         ....

    </RelativeLayout>

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

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

</LinearLayout>

我想将FrameLayout放在LinearLayout的底部,并且应该将FrameLayout中的所有元素居中。 我怎样才能做到这一点?

我不知道这是否可以解决问题,但是您可以在底部的FrameLayout中使用“ wrap_content”作为您的layout_width。 这将使FrameLayout居中,因此布局中的视图将居中。

要将按钮置于FrameLayout请添加:

android:layout_gravity="center"

Button或:

android:gravity="center"

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

框架布局中使用Layout_Gravity将起作用

 android:layout_gravity="bottom|center"

也可以使用底部边距将其从底部移至理想位置。

android:layout_marginBottom="20dp"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM