How to center a button at the bottom of a FrameLayout in a RelativeLayout
Asked Answered
B

3

5

This is my xml code:

<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>

I want to place the FrameLayout at the bottom of the LinearLayout and all elements in the FrameLayout should be centered. How can I do that?

Blockhouse answered 25/5, 2015 at 22:3 Comment(0)
N
6

In Frame Layout Use Layout_Gravity will work

 android:layout_gravity="bottom|center"

Also Use Bottom margin to make it in perfect location from bottom.

android:layout_marginBottom="20dp"
Nowadays answered 20/9, 2019 at 10:57 Comment(0)
G
1

To center the button inside the FrameLayout you should add:

android:layout_gravity="center"

inside the Button or:

android:gravity="center"

inside the FrameLayout. And btw, if a Button is the only child why are you using a FrameLayout?

Gareri answered 25/5, 2015 at 23:9 Comment(0)
S
0

I don't know exactly if that would solve the issue, but you can use "wrap_content" as your layout_width in your FrameLayout at the bottom. That would center the FrameLayout, so the views which are in the layout would get centered.

Spectre answered 25/5, 2015 at 22:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.