marginRight property of imageview not working
I have an image view whose background is a xml shape drawable i.e. a rect开发者_StackOverflowangle shape drawable.My app's orientation is fixed to landscape view.
The imageview is in relative layout.
I am trying to move it to the right of the screen by setting the appropriate value of layout_marginRight but this does not work .The imageView always stays in its's original position.
I have tried the following other options also but none helped.
The other options which I tried are:
- Creating a new relative layout params and setting the right margin
- Creating new margin layout params and setting the position
- Trying padding option
- Setting the imageview to right position relative to another imageview...
- Using display metrics to get width of screen and accordingly setting the margin....
I am stuck since a week setting the position of this imageview...
I was thinking the best approach is to set this imageview in between two imageview as I am not able to move it by setting margin but that does not work either...
Here is the current xml of my imageview in main.xml:-
<ImageView
android:id="@+id/rect1"
android:background="@drawable/rect"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginRight="70dp"
android:scaleType="fitCenter"/>
I don't see why adding a margin to the right of the image would help move the image to the right, it just extends the right side bounds of the imageview by the margin. As long as the imageview isn't actually on the right side of the parentview, it would be allowed to grow without changing position. I suggest using layout_alignParentRight="true"
on the imageview if you want it on the right of your relativelayout, and then you can use the marginRight to control how far off the right side you want it.
Make the layout_width attribute of the RelativeLayout to fill_parent and see it work :)
My issue was that my parent layout's width was set to wrap_content
, which doesn't have a defined width during the editor, I think. Thus, I couldn't use marginRight
to get an offset. I had to change the width to a fixed size like match_parent
or a constant dp size.
put the image view in a linearlayout, then use android:layout_marginRight="70dp
精彩评论