我正在使用GestureDetector.SimpleOnGestureListener的onScroll方法在画布上滚动一个大的位图。当滚动结束时,我想重新绘制位图,以防用户想要进一步滚动……离开位图的边缘,但我看不到如何检测滚动何时结束(用户将手指从屏幕上抬起)。
e2.getAction()似乎总是返回值2,所以这无济于事。e2.getPressure似乎返回相当恒定的值(大约0.25),直到最后一个onScroll调用,此时压力似乎下降到大约0.13。我想我可以察觉到压力的减少,但这远不是万无一失的。
一定有更好的方法:有人能帮上忙吗?
发布于 2010-09-29 09:09:32
下面是我是如何解决这个问题的。希望这能有所帮助。
// declare class member variables
private GestureDetector mGestureDetector;
private OnTouchListener mGestureListener;
private boolean mIsScrolling = false;
public void initGestureDetection() {
// Gesture detection
mGestureDetector = new GestureDetector(new SimpleOnGestureListener() {
@Override
public boolean onDoubleTap(MotionEvent e) {
handleDoubleTap(e);
return true;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
handleSingleTap(e);
return true;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
// i'm only scrolling along the X axis
mIsScrolling = true;
handleScroll(Math.round((e2.getX() - e1.getX())));
return true;
}
@Override
/**
* Don't know why but we need to intercept this guy and return true so that the other gestures are handled.
* https://code.google.com/p/android/issues/detail?id=8233
*/
public boolean onDown(MotionEvent e) {
Log.d("GestureDetector --> onDown");
return true;
}
});
mGestureListener = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (mGestureDetector.onTouchEvent(event)) {
return true;
}
if(event.getAction() == MotionEvent.ACTION_UP) {
if(mIsScrolling ) {
Log.d("OnTouchListener --> onTouch ACTION_UP");
mIsScrolling = false;
handleScrollFinished();
};
}
return false;
}
};
// attach the OnTouchListener to the image view
mImageView.setOnTouchListener(mGestureListener);
}
发布于 2010-02-06 21:21:46
你应该看看http://developer.android.com/reference/android/widget/Scroller.html。特别是这可能会有帮助(按相关性排序):
isFinished();
computeScrollOffset();
getFinalY(); getFinalX(); and getCurrY() getCurrX()
getDuration()
这意味着你必须创建一个滚动条。
如果你想使用触摸,你也可以使用GestureDetector并定义你自己的画布滚动。下面的示例正在创建ScrollableImageView,为了使用它,您必须定义图像的测量值。您可以定义自己的滚动范围,并在完成滚动后重新绘制图像。
http://www.anddev.org/viewtopic.php?p=31487#31487
根据您的代码,您应该考虑无效( int l,int t,int r,int b);作为无效。
发布于 2010-10-01 02:25:54
SimpleOnGestureListener.onFling()
它似乎发生在滚动结束时(即用户松开手指),这就是我正在使用的,它对我很有效。
https://stackoverflow.com/questions/2089552
复制相似问题