ImageView MotionEvent若是两个指针,则停止ACTION_UP

时间:2013-11-06 14:05:29

标签: java android motionevent

在我的活动中,我有ImageView。它具有捏缩放功能。

当我触摸ImageView时,我会显示缩略图布局。

但是当我捏住ImageView缩略图布局时。我想阻止它?

我该怎么做?

以下是我展示缩略图布局的代码:

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;
    }
});

1 个答案:

答案 0 :(得分:0)

你的openThumbnails总是如此。你在方法的开头设置它。每次触摸事件(例如Action_up,action_move)都将openThumbnail设置为true。这就是你总是展示它的原因。

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;
                    }
                });