How would I use the OnTouchEvent
function to make an ImageView
move to the right or left when the user touches the right or left of the screen? The following code is what I have tried. What could I do to improve this and make it work?
ImageView circle1 = (ImageView) findViewById(R.id.circle1);
public boolean onTouchEvent(MotionEvent MotionEvent motionEvent;
motionEvent){
switch (motionEvent.getAction() & MotionEvent.ACTION_MASK) {
// Player has touched the screen
case MotionEvent.ACTION_DOWN:
if (motionEvent.getY() > screenHeight - screenWidth / 8) {
circleIsMovingRIGHT = true;
circleIsMovingLEFT = false;
} else {
circleIsMovingRIGHT = false;
circleIsMovingLEFT = true;
}
break;
}
return true;
}
}