【发布时间】:2011-08-04 06:42:08
【问题描述】:
大家好,大家正在做一个安卓项目来实现滑动功能。 如何做到这一点。
我正在尝试使用 onfling 方法,但它对我不起作用..任何人有正确的解决方案请回复此帖子。
我的在线代码是
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if (mGesturesEnabled) {
try {
if (e2.getY() - e1.getY() > StudyOptions.sSwipeMinDistance && Math.abs(velocityY) > StudyOptions.sSwipeThresholdVelocity && Math.abs(e1.getX() - e2.getX()) < StudyOptions.sSwipeMaxOffPath && !mIsYScrolling) {
// down
executeCommand(mGestureSwipeDown);
} else if (e1.getY() - e2.getY() > StudyOptions.sSwipeMinDistance && Math.abs(velocityY) > StudyOptions.sSwipeThresholdVelocity && Math.abs(e1.getX() - e2.getX()) < StudyOptions.sSwipeMaxOffPath && !mIsYScrolling) {
// up
executeCommand(mGestureSwipeUp);
} else if (e2.getX() - e1.getX() > StudyOptions.sSwipeMinDistance && Math.abs(velocityX) > StudyOptions.sSwipeThresholdVelocity && Math.abs(e1.getY() - e2.getY()) < StudyOptions.sSwipeMaxOffPath && !mIsXScrolling && !mIsSelecting) {
// right
executeCommand(mGestureSwipeRight);
} else if (e1.getX() - e2.getX() > StudyOptions.sSwipeMinDistance && Math.abs(velocityX) > StudyOptions.sSwipeThresholdVelocity && Math.abs(e1.getY() - e2.getY()) < StudyOptions.sSwipeMaxOffPath && !mIsXScrolling && !mIsSelecting) {
// left
executeCommand(mGestureSwipeLeft);
}
mIsXScrolling = false;
mIsYScrolling = false;
} catch (Exception e) {
Log.e(AnkiDroidApp.TAG, "onFling Exception = " + e.getMessage());
}
}
return false;
}
【问题讨论】:
-
下次请使用格式化按钮格式化您的代码。我已经为你编写了它,但它仍然需要对缩进进行一些调整。另外,添加“它不起作用”的意思。这是做什么的,你期望它做什么(以及为什么),你的日志说什么等等。多一点努力会更容易回答这个