How to install a button in a fixed place at the bottom of the user interface?

I want the button to appear in a fixed place all the time, in the footer of the user interface? (always if it has components above it or not)

+6
source share
5 answers

Take one relative layout for your main layout. Set its height and width to fill the parent element and set its gravity to the bottom and place any text image or any button that you need.

<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="bottom"> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Bottom Gravity" /> </RelativeLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content"> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Without Gravity" /> </LinearLayout> </FrameLayout> 

enter image description here

+22
source

It depends on the layout you use.

In RelativeLayout there is

 android:layout_alignParentBottom="true" 

In the LinearLayout, place it at the bottom and make sure the layoutsweight elements are set correctly.

Also check property

 android:layout_gravity 

and notice that it is different from

 android:gravity 
+6
source

Set android:layout_gravity="bottom" . Hope this helps.

+2
source

Placed

 android:layout_alignParentBottom="true" 

in your relative layout.

0
source

If someone has two buttons, you can just do it for me.

 <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="bottom"> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="bottom" > <android.support.v7.widget.AppCompatButton android:id="@+id/btn_yes" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="12dp" android:text="Valider"/> <android.support.v7.widget.AppCompatButton android:id="@+id/btn_no" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="12dp" android:text="Annuler"/> </LinearLayout> </RelativeLayout>` 
0
source

Source: https://habr.com/ru/post/891629/


All Articles