android Gallery 实现短距离滚动 取消惯性
这几天项目需要用到Gallery,经过开发将几个要点记录下来:
自己继承实现Gallery?
?
public class MyGallery extends Gallery
?
1 去除翻页惯性
重写?onFling方法
?
@Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { // 或者直接return false return super.onFling(e1, e2, 0, velocityY); }?2??实现短距离滚动
?
@Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { int kEvent; if (isScrollingLeft(e1, e2)) { // Check if scrolling left kEvent = KeyEvent.KEYCODE_DPAD_LEFT; } else { // Otherwise scrolling right kEvent = KeyEvent.KEYCODE_DPAD_RIGHT; } onKeyDown(kEvent, null); return true; }?
?
private boolean isScrollingLeft(MotionEvent e1, MotionEvent e2) { return e2.getX() > e1.getX(); }???
Open link in current tab