How do I centralize the button in Relative Layout?

Asked 2 years ago, Updated 2 years ago, 79 views

I'd like to print out the button in the center of relative layout What should I do? No matter how much you touch the gravity and orientation, it's useless.

android layout

2022-09-22 22:09

1 Answers

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:background="#ff0000">

    <Button
        android:id="@+id/btn_mybutton"
        android:layout_height="wrap_content"
        android:layout_width="124dip"
        android:layout_marginTop="5dip"
        android:layout_centerHorizontal="true"/>

</RelativeLayout>

Do it like this. If you want it to be in the middle of the screen, android:layout_centerVertical="true" should also be provided.


2022-09-22 22:09

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.