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 に答える