Hello
I've set up an onTouchListener within my application for an ImageView, my aim was to have an ImageView that the user would be able to drag around and place where ever they want within the app.
I've written some code using sample code found on the web for an onTouchListener that I thought would work but I'm having some problems with it, rather than allowing me to drag the image around, the image resizes and gets bigger or smaller when you drag your finger over it.
Does anyone have any ideas why?
Here's my code:
ImageView t1img;
t1img = (ImageView) findViewById(R.id.imgT1);
windowWidth = getWindowManager().getDefaultDisplay().getWidth();
windowHeight = getWindowManager().getDefaultDisplay().getHeight();
t1img.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
layoutParams = (LayoutParams) t1img.getLayoutParams();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_MOVE:
int xCoord = (int) event.getRawX();
int yCoord = (int) event.getRawY();
if (xCoord > windowWidth) {
xCoord = windowWidth;
}
if (yCoord > windowHeight) {
yCoord = windowHeight;
}
layoutParams.leftMargin = xCoord - 25;
layoutParams.topMargin = yCoord - 75;
t1img.setLayoutParams(layoutParams);
break;
default:
break;
}
return true;
}
});