0

我有一个 ImageButton,当我按下它并按住手指时它变得不可见,当我抬起手指时它又变得可见。

但是当我按下按钮并且当我的手指向下时我将它从它移开并将它抬起它不会再次变得可见

代码看起来像这样

final ImageButton b=(ImageButton)findViewById(R.id.timer_btn);

        b.setOnTouchListener(new View.OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()) {

                  case MotionEvent.ACTION_UP: 
                        b.setVisibility(View.VISIBLE);
                        Log.w("app", "Action up");
                        return true;
                  case MotionEvent.ACTION_DOWN: 
                        b.setVisibility(View.INVISIBLE);
                        Log.w("app", "Action down");

                       }
                    return false;
            }
        });

我尝试使用

case MotionEvent.ACTION_OUTSIDE: 
                            b.setVisibility(View.VISIBLE);
                            Log.w("app", "Action outside");

                           }

但它不起作用,无论它是在按钮外部还是内部,它都会被调用

4

1 回答 1

1

你必须使用ACTION_CANCEL. 我猜 ACTION_OUSIDE 是在实际屏幕之外的。

系统将始终调用 UP 或 CANCEL。

编辑:

我相信这应该有效:

              case MotionEvent.ACTION_CANCEL: 
              case MotionEvent.ACTION_UP: 
                    b.setVisibility(View.VISIBLE);
                    Log.w("app", "Action up");
                    return true;
于 2013-01-09T15:48:13.980 回答