Android - 触摸事件停止工作

时间:2011-10-04 14:13:33

标签: android

这是我的触摸事件:

.myImageViewsetOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_MOVE:
//OUTPUT TRACE

问题是,在移动一下后,它会停止在动作移动下输出。

我做错了什么?

myImageView.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {

            int myX = (int)event.getX();
            int myY = (int)event.getY();
            int color = pngTestBM.getPixel(myX,myY); // x and y are the location of the touch event in Bitmap space
            int alpha = Color.alpha(color);

            switch (event.getAction()) {


            case MotionEvent.ACTION_DOWN:


                if(alpha==0){
                    System.out.println("blank");
                }
                else{
                    System.out.println("no");

                }


            break;

            case MotionEvent.ACTION_UP:

            break;

            case MotionEvent.ACTION_MOVE:



                if(alpha==0){
                    System.out.println("blank");

                }
                else{
                    System.out.println("no");
                }



            break;

            }
            return true;
        }
    });

1 个答案:

答案 0 :(得分:0)

尝试使用此方法进行调试。在开始时调用它。还添加默认案例。顺便说一句..使用Log.d而不是System.out

private void dumpEvent(MotionEvent event) {
          String names[] = { "DOWN" , "UP" , "MOVE" , "CANCEL" , "OUTSIDE" ,
             "POINTER_DOWN" , "POINTER_UP" , "7?" , "8?" , "9?" };
          StringBuilder sb = new StringBuilder();
          int action = event.getAction();
          int actionCode = action & MotionEvent.ACTION_MASK;
          sb.append("event ACTION_" ).append(names[actionCode]);
          if (actionCode == MotionEvent.ACTION_POINTER_DOWN
                || actionCode == MotionEvent.ACTION_POINTER_UP) {
             sb.append("(pid " ).append(
             action >> MotionEvent.ACTION_POINTER_ID_SHIFT);
             sb.append(")" );
          }
          sb.append("[" );
          for (int i = 0; i < event.getPointerCount(); i++) {
             sb.append("#" ).append(i);
             sb.append("(pid " ).append(event.getPointerId(i));
             sb.append(")=" ).append((int) event.getX(i));
             sb.append("," ).append((int) event.getY(i));
             if (i + 1 < event.getPointerCount())
                sb.append(";" );
          }
          sb.append("]" );
          Log.d("event", sb.toString());
       }