gpt4 book ai didi

java - ImageView MotionEvent如果有两个指针,则停止ACTION_UP

转载 作者:行者123 更新时间:2023-12-01 04:12:08 26 4
gpt4 key购买 nike

在我的 Activity 中,我有一个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;
}
});

最佳答案

您的 openThumbnails 始终为 true。您可以在方法开始时设置它。每个触摸事件(例如 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;
}
});

关于java - ImageView MotionEvent如果有两个指针,则停止ACTION_UP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19814170/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com