我在 Android 中有一个 Imageview,我需要在单击图像时显示弹出窗口,并且还需要在两指交叉时缩放图像。
我尝试使用以下代码。你能请任何人帮助我吗?
谢谢。
image = (ImageView) findViewById(R.id.image);
GestureDetector gdt = new GestureDetector(new GestureListener());
image.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(final View view, final MotionEvent event) {
gdt.onTouchEvent(event);
return true;
}
});
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
private class GestureListener extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
return false; // Right to left
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
return false; // Left to right
}
if(e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
return false; // Bottom to top
} else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
return false; // Top to bottom
}
return false;
}
}
最佳答案
您介意使用 Chris Banes 本人的库来缩放 ImageView 吗?
关于android - Imageview 在 android 中单击和双击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45321596/