Ankit
Ankit

Reputation: 4644

How to place a button at a position little above the bottom in android

I need to place a button at the bottom of screen, leaving some space below it. In other words I am using these two attributes for my button -

android:layout_alignParentBottom="true" 
android:layout_marginBottom="20dp"

but the margin attribute wont work when I use alignParentBottom and the button sticks at the bottom only. Please tell me how to place it a little above the bottom .

Here's the xml

<RelativeLayout
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:gravity="center_horizontal"
 android:background="@drawable/board"
 android:layout_marginLeft="10dp"
 android:layout_marginRight="60dp"
 android:layout_marginTop="15dp"
 android:layout_marginBottom="10dp">


        <TextView 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:text="Type of Lesion"
            android:textColor="#8B0A50"
            android:layout_marginTop="40dp"
            android:id="@+id/disease_listheader_textview"
             android:drawableBottom="@drawable/underline"/>

        <ListView 
          android:id="@+id/disease_listview"
          android:layout_below="@id/disease_listheader_textview"
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content"
          android:divider="@drawable/divider"
          android:layout_marginLeft="40dp"
          android:layout_marginBottom="50dp"
          android:cacheColorHint="#00000000"/>  

        <Button  
             android:layout_width="wrap_content" 
             android:layout_height="wrap_content"
             android:id="@+id/disease_search_button"
             android:layout_centerHorizontal="true"
             android:background="@drawable/disease_search_btn" 
             android:layout_alignParentBottom="true"
             android:layout_marginBottom="20dp"/>

     </RelativeLayout>

Upvotes: 1

Views: 715

Answers (3)

Rahul Choudhary
Rahul Choudhary

Reputation: 3809

Can you try this?

  1. Replace the Button tag with the one mentioned below. I am trying to wrap the button in another dummy layout

    <LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    android:paddingBottom="20dp">
    
    <Button  
             android:layout_width="wrap_content" 
             android:layout_height="wrap_content"
             android:id="@+id/disease_search_button"
             android:background="@drawable/disease_search_btn" 
             android:layout_marginBottom="20dp"/>
    
    </LinearLayout>
    

Upvotes: 1

Vijay
Vijay

Reputation: 2005

just make change in relative layout height attribute value to fillparent like

<RelativeLayout
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
  .................../>


hope this help you

Upvotes: 3

Lukap
Lukap

Reputation: 31963

This runs just the way you wanted

<RelativeLayout android:id="@+id/relativeLayout1" android:layout_width="match_parent" android:layout_height="fill_parent">
    <Button android:text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginBottom="20dip"></Button>
</RelativeLayout>

Upvotes: 0

Related Questions