0

我有两个不可见的区域用作按钮,当我单击特定区域时,它会增加位图的速度,但前提是我反复按下它。如何让它在 LongPressed 上工作以增加位图的速度?

这是我的代码:

 public boolean onTouchEvent(MotionEvent event) {

                if((event.getX(0)>=1) && 
                          (event.getY(0)>=500) && 
                         ( event.getX(0)<=1+150) && 
                          (event.getY(0)<=500+300))
                          {


                    u--;        

                          }

                if((event.getX(0)>=300) && 
                      (event.getY(0)>=500) && 
                     ( event.getX(0)<=300+150) && 
                      (event.getY(0)<=500+300))
                      {

                u++;

                      }


                       return true; 

        }
4

1 回答 1

0

尝试这个

final GestureDetector gestureDetector = new GestureDetector(new GestureDetector.SimpleOnGestureListener() {
public void onLongPress(MotionEvent e) {
    Log.e("", "Longpress detected");
    }
 });

public boolean onTouchEvent(MotionEvent event) {
    return gestureDetector.onTouchEvent(event);
};
于 2013-06-26T11:14:43.070 回答