I want a button to appear at fixed location all the time, in the footer of the UI ؟ ( always, if it has components above it or not )
            Asked
            
        
        
            Active
            
        
            Viewed 5.6k times
        
    5 Answers
32
            Please take one Relative layout under your main layout . Set its height and width as fill parent and set its gravity as bottom and put any textview or any button you want in it.
 <?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>

- 
                    1Perfect Answer. Works. But should use "match_parent" instead of "fill_parent" – rjdthegreat Jan 09 '16 at 20:53
- 
                    It works perfectly, but any clues if there is anyway to the button being not elevated by keyboard? – vinicius gati Jun 14 '18 at 11:56
- 
                    thanks a lot. It worked for me. I had the nesting of Linearlayout. One of them I changed to RelativeLayout with the attributes and values as you specified and It worked perfectly. – Vijay Aug 17 '19 at 14:18
6
            
            
        It depends on the layout you are using.
On a RelativeLayout there is
android:layout_alignParentBottom="true"
On a LinearLayout, place it at the bottom and make sure to set the elements layout_weight properly.
Also, check the property
android:layout_gravity
and notice it's different than
android:gravity
 
    
    
        Maragues
        
- 37,861
- 14
- 95
- 96
- 
                    i confirm your answer , he should use a relativeLayout to fixe the button at the bottom with `android:layout_alignParentBottom="true"`, and i want just to add that if he want to keep his button to the front , in his code he can call the method : `btn.bringToFront()` – Houcine Jun 29 '11 at 11:00
1
            
            
        Put
android:layout_alignParentBottom="true"
in your relative layout.
 
    
    
        michaelb958--GoFundMonica
        
- 4,617
- 7
- 31
- 35
 
    
    
        jigar
        
- 1,571
- 6
- 23
- 46
1
            
            
        if any one have two button you can just make this it orks 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>`
 
    
    
        na3na3iss
        
- 65
- 1
- 1
- 10
 
     
     
     
    