开发者

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

开发者 https://www.devze.com 2023-04-07 05:23 出处:网络
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 -

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_marginB开发者_StackOverflowottom="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>


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


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>
    


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

精彩评论

暂无评论...
验证码 换一张
取 消