I'm having this weird issue with a custom TextView I'm working on. I'm trying to move the view by dragging it with a finger, so I get the touch position, do some math, and set the corresponding leftMargin and topMargin. It works, but I get some very weird behavior. The leftMargin part works perfectly, but the topMargin is very jumpy. It seems like it oscillates between the correct position and a position 25 pixels below it. When I only tap on the view instead of continuously dragging it, it moves down 25 pixels with every touch. Does anyone have any idea why this could be? The relevant code is here:
case MotionEvent.ACTION_MOVE :
{
final float x = event.getX();
final float y = event.getY();
final float newMarginX;
final float newMarginY;
positionX = x;
positionY = y;
newMarginX = oldMarginX - (lastTouchX - positionX);
newMarginY = oldMarginY - (lastTouchY - positionY);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(this.getWidth(), this.getHeight());
params.leftMargin = (int) newMarginX;
params.topMargin = (int) newMarginY;
this.setLayoutParams(params);
this.setText(Float.toString(y));
lastTouchX = positionX;
lastTouchY = positionY;
oldMarginX = newMarginX;
oldMarginY = newMarginY;
break;
}