Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set negative margin on ImageView shifts ImageView but not Image

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.
like image 626
User Avatar asked Apr 20 '12 12:04

User


2 Answers

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>
like image 59
User Avatar answered Sep 21 '22 04:09

User


If your container have enough padding you can set its clipToPadding to false and use negative margin!

like image 33
Ali Avatar answered Sep 19 '22 04:09

Ali