开发者

Android - Touch event stops working

This is my touch event:

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

The problem is, after moving around a bit, it stops outputing under action move.

What am I doing wrong?

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;

            c开发者_JAVA技巧ase MotionEvent.ACTION_UP:

            break;

            case MotionEvent.ACTION_MOVE:



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

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



            break;

            }
            return true;
        }
    });


try debugging using this method. Call it at the beginning. Also add a default case. btw.. use Log.d instead of 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());
       }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜