Java MotionEvent.ACTION\u UP不工作

Java MotionEvent.ACTION\u UP不工作,java,android,padding,ontouchlistener,Java,Android,Padding,Ontouchlistener,我有两个图像,我作为操纵杆使用MotionEvent.ACTION\u DOWN工作正常,正在以正确的方向填充图像MotionEvent.ACTION\u UP假定将图像返回其默认位置,但不起作用。以下是我的侦听器代码: //First joystick listener joystick1.setOnTouchListener(new OnTouchListener(){ public boolean onTouch(View v, MotionEvent event

我有两个图像,我作为操纵杆使用<代码>MotionEvent.ACTION\u DOWN工作正常,正在以正确的方向填充图像
MotionEvent.ACTION\u UP
假定将图像返回其默认位置,但不起作用。以下是我的侦听器代码:

//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;
        }

    });
//第一个操纵杆侦听器
joystick1.setOnTouchListener(新的OnTouchListener(){
公共布尔onTouch(视图v,运动事件){
Log.d(“TouchTest”,event.toString());
//获取用户触摸时用户触摸的X和Y值
//操纵杆移动图像
X=event.getX();
Y=event.getY();
CY=cursor.getHeight()/2;
CX=cursor.getWidth()/2;
joystick1Move=true;
int action=event.getAction();
开关(动作){
case MotionEvent.ACTION\u DOWN:
日志d(“触地测试”、“触地”);
//如果用户触摸了图像并将手指左右移动
//上下移动第一个操纵手柄,然后移动操纵手柄图像
如果(X>(操纵杆宽度/2)和&X