MarginRight property not working

I have a view of an image whose background is an xml shape, that is, a rectangle shape suitable for drawing. My application orientation is tied to the landscape view.

Image is in relative layout.

I am trying to move it to the right of the screen by setting the appropriate layout_marginRight value, but this will not work. ImageView is always in the starting position.

I also tried the following other options, but no one helped.

Other options I tried:

  • Creating new relative placement parameters and setting the correct field
  • Creating new field layout options and setting a position
  • Gasket Run Option
  • Setting the image to the desired position relative to another image ...
  • Using display metrics to get the width of the screen and, accordingly, setting the field ....

I’ve been stuck for a week setting the position of this image ...

I thought the best approach is to set this image between two images, since I cannot move it by setting a field, but this also does not work.

Here is the current xml of my image 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"/> 
+7
source share
4 answers

I don’t understand why adding a field to the right of the image will help to move the image to the right, it just extends the borders of the side frame of the image along the edge. As long as the image is not actually located to the right of the parent view, it will be allowed to grow without changing the position. I suggest using layout_alignParentRight="true" in the image view if you want it to be to the right of your relativity, and then you can use marginRight to control how far you want from it.

+6
source

Make the layout_width attribute for RelativeLayout for fill_parent and see how it works :)

+1
source

My problem was that my parent layout width was set to wrap_content , which, it seems to me, does not have a specific width during editing. Thus, I could not use marginRight to get the offset. I had to change the width to a fixed size like match_parent or constant dp size.

0
source

put the image view in linearlayout, then use android: layout_marginRight = "70dp

-2
source

All Articles