Open captain-miao opened 10 years ago
In class GestureImageViewTouchListener
tapDetector = new GestureDetector(image.getContext(), new SimpleOnGestureListener() {
@Override
public boolean onDoubleTap(MotionEvent e) {
startZoom(e);
return true;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
if(!inZoom) {
if(onClickListener != null) {
onClickListener.onClick(image);
return true;
}
}
return false;
}
@Override
public void onLongPress(MotionEvent e) {
if(!inZoom) {
if(onLongClickListener != null) {
onLongClickListener.onLongClick(image);
}
}
super.onLongPress(e);
}
});
add OnLongClickListener
should be ok.
Firstly you should add OnLongClickListener like what b>@venciallee</b said,but that does not work correctly cause under this situation "DoubleTap" while call OnLongPress,so you should do something to prevent the "OnLongPress" event is called back. the following is my solution: 1、setIsLongPressedEnabled(false) in onDoubleTap,like:
tapDetector = new GestureDetector(image.getContext(), new SimpleOnGestureListener() {
@Override
public boolean onDoubleTap(MotionEvent e) {
startZoom(e);
tapDetector.setIsLongpressEnabled(false);
return true;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
if(!inZoom) {
if(onClickListener != null) {
onClickListener.onClick(image);
return true;
}
}
return false;
}
@Override
public void onLongPress(MotionEvent e) {
if(!inZoom) {
if(onLongClickListener != null) {
onLongClickListener.onLongClick(image);
}
}
super.onLongPress(e);
}
} );
2、Restore IsLongPressedEnable to true in the ZoomAnimationListener.onComplete(),like this:
zoomAnimation.setZoomAnimationListener(new ZoomAnimationListener() {
@Override
public void onZoom(float scale, float x, float y) {
if(scale <= maxScale && scale >= minScale) {
handleScale(scale, x, y);
}
}
@Override
public void onComplete() {
inZoom = false;
handleUp();
tapDetector.setIsLongpressEnabled(true);
}
});
hope this can help u.
onLongClick not working in ViewPager. onClick() is working.