Take the 2-minute tour ×

I have an imageview that moves around the screen. So, I've set the LayoutParams to do it. But, the android insists on resize my imageview. How can I prevent this behavior?

public void move(int x, int y)
    width = this.getWidth();
    height = this.getHeight();
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(WIDTH, HEIGHT);
    int t = validateMin(calcTopPos(y));
    int l = validateMin(calcLeftPos(x));
    int r = validateMaxWidth(calcRightPos(x))-1;
    int b = validateMaxHeight(calcBottomPos(y));
    params.setMargins(l, t, r, b);
share|improve this question
Could you post the layout.xml? –  Andrew T. Oct 25 '13 at 0:49
And while you are at it, rename those uppercase local variables to width and height ;) –  Martín Marconcini Oct 25 '13 at 0:52
@MartínMarconcini is correct, you shouldn't use uppercase for variables that are not final/constants :) –  codebringer Oct 25 '13 at 1:18

1 Answer 1

I've found the answer: android:adjustViewBounds = "true" in the xml file. But, I still don't know why android was resizing my view. It's a mystery!

share|improve this answer

Your Answer


