简体   繁体   中英

ImageView MotionEvent if two pointer, stop ACTION_UP

In my activity I have an ImageView . It has pinch-zoom feature.

When I touch on ImageView I show thumbnails layout.

But when I pinch on ImageView thumbnail layout shows. I want to block it?

How can I do it?

Here is my code to show thumbnail layout:

image.setOnTouchListener(new OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        Boolean openThumbnails=true;
        if(event.getAction() == MotionEvent.ACTION_UP && openThumbnails){
            Log.e("event.getAction()", "MotionEvent.ACTION_UP");
            if(thumbnailsLayout.getVisibility()==View.GONE && header.getVisibility()==View.GONE && openThumbnails){
                thumbnailsLayout.setVisibility(View.VISIBLE);
                header.setVisibility(View.VISIBLE);
                header.bringToFront();
            }
            else{
                thumbnailsLayout.setVisibility(View.GONE);
                header.setVisibility(View.GONE);
            }
        }
        else if(event.getAction() == MotionEvent.ACTION_DOWN){
            Log.e("event.getAction()", "MotionEvent.ACTION_DOWN");
            return true;
        }
        else if(event.getAction()==MotionEvent.ACTION_MOVE){
            Log.e("openThumbnails before", openThumbnails.toString());
            openThumbnails=false;        
            Log.e("openThumbnails and after", openThumbnails.toString());
        }
        return false;
    }
});

Your openThumbnails is always true. You set it at the start of method. Every touch event (eg Action_up, action_move) you set openThumbnail to true. That's why you always show it.

image.setOnTouchListener(new OnTouchListener() {
Boolean openThumbnails=true;
                    @Override
                    public boolean onTouch(View v, MotionEvent event) {

                        if(event.getAction() == MotionEvent.ACTION_UP && openThumbnails){
                            Log.e("event.getAction()", "MotionEvent.ACTION_UP");
                            if(thumbnailsLayout.getVisibility()==View.GONE && header.getVisibility()==View.GONE && openThumbnails){
                                thumbnailsLayout.setVisibility(View.VISIBLE);
                                header.setVisibility(View.VISIBLE);
                                header.bringToFront();
                            }
                            else{
                                thumbnailsLayout.setVisibility(View.GONE);
                                header.setVisibility(View.GONE);
                            }
                        }
                        else if(event.getAction() == MotionEvent.ACTION_DOWN){
                            Log.e("event.getAction()", "MotionEvent.ACTION_DOWN");
                            return true;
                        }
                        else if(event.getAction()==MotionEvent.ACTION_MOVE){
                            Log.e("openThumbnails before", openThumbnails.toString());
                            openThumbnails=false;       
                            Log.e("openThumbnails and after", openThumbnails.toString());
                        }
                        return false;
                    }
                });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM