Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bottom margin or padding doesn't work in relative layout in xml on android

I have a RelativeLayout for a row that goes inside a ListView. The row looks like,

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout1" 
    android:layout_width="wrap_content"
    android:layout_height="fill_parent">

    <ImageView
        android:id="@+id/placeDetailIcon_Img"
        android:layout_height="50dp"
        android:layout_width="50dp"
        android:layout_alignParentLeft="true" 
        android:paddingBottom="20dp"
        android:paddingTop="20dp" 
        android:paddingLeft="20dp"
        android:paddingRight="20dp"/>
</RelativeLayout>

I also tried it with margin:

 <ImageView
    android:layout_height="50dp"
    android:layout_width="50dp"
    android:id="@+id/placeDetailIcon_Img" 
    android:layout_alignParentLeft="true" 
    android:layout_marginRight="10dp"
    android:layout_marginTop="10dp"
    android:layout_marginLeft="10dp"
    android:layout_marginBottom="10dp">

Neither apply the margin or padding around the ImageView. How do create this type of spacing?

like image 360
Atma Avatar asked Apr 19 '12 21:04

Atma


2 Answers

you can use this its work with me :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">  

     <ImageView
         android:id="@+id/imageView1"
         android:layout_width="50dp"
         android:layout_height="50dp"
         android:layout_alignParentLeft="true"
         android:layout_alignParentTop="true"
         android:layout_marginLeft="15dp"
         android:layout_marginTop="15dp" />

</RelativeLayout>

hope this helps.

like image 199
Android Stack Avatar answered Nov 20 '22 21:11

Android Stack


For anyone else who is looking for a solution to this - from the docs:

http://developer.android.com/reference/android/widget/RelativeLayout.html

"Note that you cannot have a circular dependency between the size of the RelativeLayout and the position of its children. For example, you cannot have a RelativeLayout whose height is set to WRAP_CONTENT and a child set to ALIGN_PARENT_BOTTOM."

It seems also that there is some odd behavior if you put a relativeView inside of a scrollview.

In my case I had set the relativeLayout to wrap_content and then tried to add marginBottom to an ImageView with the ALIGN_PARENT_BOTTOM attribute. When I set the height explicitly it finally worked.

like image 43
bkurzius Avatar answered Nov 20 '22 21:11

bkurzius