1

Imagebuttonがあり、ActionDOWNにsetColorFilterを設定しましたが、ユーザーがImageButtonから指をスライドさせた場合、setColorFilterが適用されたままになります。

質問:

  • 指が滑り落ちるのを検出する方法は?次に、setColorFilter(null);を適用できます。

    ImageButton i1 =(ImageButton)v.findViewById(R.id.imageButton1); i1.setOnTouchListener(new OnTouchListener(){

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
                ImageButton button = (ImageButton)v;
                String principal = "principal";
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    button.setColorFilter(0x8066bbdd);
                    return true;
                } else if (event.getAction() == MotionEvent.ACTION_UP) {
                    button.setColorFilter(null);
                    Intent i = new Intent(getActivity(), SubView.class);
                    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    i.putExtra("query", principal);
                    startActivity(i);
                    return true;
                }
                return false;
            }
        });
    
4

1 に答える 1

1

使用できますMotionEvent.ACTION_OUTSIDE

ImageButton i1 = (ImageButton)v.findViewById(R.id.imageButton1); i1.setOnTouchListener(new OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        // TODO Auto-generated method stub
        ImageButton button = (ImageButton)v;
        String principal = "principal";
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            button.setColorFilter(0x8066bbdd);
            return true;
        } else if (event.getAction() == MotionEvent.ACTION_UP) {
            button.setColorFilter(null);
            Intent i = new Intent(getActivity(), SubView.class);
            i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            i.putExtra("query", principal);
            startActivity(i);
            return true;
        } else if(event.getAction() == MotionEvent.ACTION_OUTSIDE)
        {

            // Do some stuffs here
        }

        return false;
    }
});

更新1:

MotionEvent.ACTION_OUTSIDEうまくいかない場合は、試すことができますMotionEvent.ACTION_CANCEL

于 2013-01-19T13:37:42.187 に答える