MotionEvent.ACTION_UP not working

I have two images that I use as joysticks. MotionEvent.ACTION_DOWN works fine and fills the images in the right direction. MotionEvent.ACTION_UP Suppose to return an image to its original position, but it does not work. Here is my code for the listener:

 //First joystick listener joystick1.setOnTouchListener(new OnTouchListener(){ public boolean onTouch(View v, MotionEvent event) { Log.d("TouchTest", event.toString()); //Gets the X and Y values of the users touch when the user is touching //the joystick move image X = event.getX(); Y = event.getY(); CY = cursor.getHeight()/2; CX = cursor.getWidth()/2; joystick1Move = true; int action = event.getAction(); switch (action){ case MotionEvent.ACTION_DOWN: Log.d("TouchTest", "Touch down"); //if the user has touched the image and moves finger right left //up and down for the first joystick then move the joystick image if(X>(joystick1width/2)&&X<(v.getWidth())){ //right CX=CX+5; joystick1.setPadding(20, 0, 0, 0); } if(X<(joystick1width/2)){ //left CX=CX-5; joystick1.setPadding(-20, 0, 0, 0); } if(Y>(joystick1height/2)&&Y<(v.getHeight())){ //up CY=CY+5; joystick1.setPadding(0, 0, 0, 20); } if(Y<(joystick1height/2)){ //down CY=CY-5; joystick1.setPadding(0,0, 0, -20); } break; case MotionEvent.ACTION_UP: Log.d("TouchTest", "Touch up"); joystick1.setPadding(0, 0, 0, 0); break; default: Log.d("TouchTest", "Touch up"); joystick1.setPadding(0, 0, 0, 0); } return true; } }); 
+4
source share

Source: https://habr.com/ru/post/1388979/


All Articles