当我以水平方式使用捏拉缩放手势时,总是在达到按下的坐标和释放坐标的某个差异时调用滑动功能。
我该如何解决这个问题?
这是webview的设置
view.getSettings().setBuiltInZoomControls(true);
view.getSettings().setSupportZoom(true);
view.getSettings().setDisplayZoomControls(false);
滑动功能
protected void swipePage(View v, MotionEvent event, int book) {
int action = MotionEventCompat.getActionMasked(event);
switch (action) {
case (MotionEvent.ACTION_DOWN):
swipeOriginX = event.getX();
swipeOriginY = event.getY();
break;
case (MotionEvent.ACTION_UP):
int quarterWidth = (int) (screenWidth * 0.3);
float diffX = swipeOriginX - event.getX();
float diffY = swipeOriginY - event.getY();
float absDiffX = Math.abs(diffX);
float absDiffY = Math.abs(diffY);
if ((diffX > quarterWidth) && (absDiffX > absDiffY)) {
try {
navigator.goToNextChapter(index);
} catch (Exception e) {
errorMessage(getString(R.string.error_cannotTurnPage));
}
} else if ((diffX < -quarterWidth) && (absDiffX > absDiffY)) {
try {
navigator.goToPrevChapter(index);
} catch (Exception e) {
errorMessage(getString(R.string.error_cannotTurnPage));
}
}
break;
}
}
答案 0 :(得分:0)
检查是否有效 - 如果有单指触摸,则检查if条件,然后只进行滑动。将“event”变量更改为您的本地变量。
if(event.getPointerCount() == 1)
{
switch (action) {
case (MotionEvent.ACTION_DOWN):
swipeOriginX = event.getX();
swipeOriginY = event.getY();
break;
case (MotionEvent.ACTION_UP):
int quarterWidth = (int) (screenWidth * 0.3);
float diffX = swipeOriginX - event.getX();
float diffY = swipeOriginY - event.getY();
float absDiffX = Math.abs(diffX);
float absDiffY = Math.abs(diffY);
if ((diffX > quarterWidth) && (absDiffX > absDiffY)) {
x = 1;
try {
navigator.goToNextChapter(index);
x = 0;
} catch (Exception e) {
x = 1;
errorMessage(getString(R.string.error_cannotTurnPage));
}
} else if ((diffX < -quarterWidth) && (absDiffX > absDiffY)) {
x = 1;
try {
navigator.goToPrevChapter(index);
x = 0;
} catch (Exception e) {
x = 1;
errorMessage(getString(R.string.error_cannotTurnPage));
}
break;
}
}
}
else if(event.getPointerCount()==2)
{
// code for pinch zoom
}