pre*_*bgg 65 android smooth-scrolling android-canvas
我正在使用GestureDetector.SimpleOnGestureListener的onScroll方法在画布上滚动一个大位图.当滚动结束时,我想重绘位图,以防用户想要进一步滚动...离开位图的边缘,但我看不到如何检测滚动何时结束(用户已抬起手指)从屏幕上).
e2.getAction()似乎总是返回值2,所以没有帮助.当压力似乎下降到0.13左右时,e2.getPressure似乎返回相当恒定的值(大约0.25)直到最后的onScroll调用.我想我可以发现这种压力减少,但这远非万无一失.
必须有更好的方法:请有人帮忙吗?
Ako*_* Cz 67
这是我解决问题的方法.希望这可以帮助.
// 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);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
53899 次 |
| 最近记录: |