Android – Set negative margin on ImageView shifts ImageView but not Image

androidimageviewlayout

I Need to shift an ImageView, which is a direct child of a LinearLayout, a bit to the left.

What happens: The View is shifted (can see the "bounding box" is shifted, with android layout manager) but the drawable keeps in the same place.

Also the drawable is cut on the right side, if I set margin low enough.

enter image description here

Why is this? Any advice?

  • Clarification: I have to shift the Image to the left. That means a bit ouside of the bounds of the containing layout.

Best Answer

It seems elements are always clipped when they get outside of parent's bounds (also with clipChildren=false).

A solution is to create an additional container-layout for everything besides of the item to be shifted. And then shift the container-layout 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>