Gallery 取消惯性滚动 & 实现短距离滚动
Gallery 组件的特点:惯性滚动 与 半屏翻页。
?
取消惯性滚动 与 实现短距离滚动:
?
public class DetialGallery extends Gallery { public DetialGallery(Context context, AttributeSet attrSet) { // TODO Auto-generated constructor stub super(context, attrSet); } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { // TODO Auto-generated method stub // 只需要去除翻页惯性 - 方法1: // return super.onFling(e1, e2, 0, velocityY); // 只需要去除翻页惯性 - 方法2: // return false; // 实现短距离滚动: 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(); } }
?