Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android:layout_marginRight attribute not working on RelativeLayout

I have an Inner relative layout with 2 images, and when I set the android:layout_marginRight attribute it doesn't do anything.

Here is my code:

<RelativeLayout
    android:id="@+id/location_image_layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true" >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="80dp" />

    <ImageView
        android:layout_width="69.33dp"
        android:layout_height="72dp"
        android:background="@drawable/icon"
        android:layout_centerInParent="true" />

</RelativeLayout>
like image 538
meh Avatar asked Oct 28 '12 14:10

meh


2 Answers

The problem is in the layout's property android:layout_width. When it is set to "wrap_content",the android:layout_marginRight won't working, but rather, only when it is set to "fill_parent", the android:layout_marginRight will work.

like image 200
mokeyking Avatar answered Sep 23 '22 01:09

mokeyking


You have used the following thats why it is happening

android:layout_alignParentRight="true"

just remove this line you will get the margin from the right in your imageview..

like image 24
Arpit Patel Avatar answered Sep 24 '22 01:09

Arpit Patel