Set negative margin on ImageView shifts ImageView, but not image

I need to transfer the ImageView, which is a direct descendant of LinearLayout, a little to the left.

What happens: the view is shifted (you can see that the "bounding box" is shifted, with the Android layout manager), but the stitched one remains in one place.

Also cut out on the right side if I set the edge low enough.

enter image description here

Why is this? Any tips?

  • Clarification: I need to shift the image to the left. This means slightly smaller borders of the containing layout.
+6
source share
3 answers

It seems that elements are always clipped when they go beyond the boundaries of their parents (also using clipChildren = false).

The solution is to create an additional mock container for everything except the item you want to move. And then move the layout container in the opposite direction.

For example, to shift -10dip:

<Original container ...> <Item to be shifted/> <New container with margin 10dip> <Previous content of Original container ... /> </New container with margin 10dip> </Original container> 
+4
source

If your container has enough padding, you can set clipToPadding to false and use a negative margin!

+3
source

Why are you using negative margin? use the positive a bit more on the opposite side of the ImageView in the direction you want to shift the image, i.e. if you want to shift the image to the left, use the more positive field on the right.

+1
source

Source: https://habr.com/ru/post/913725/


All Articles