`
jiangyang5157
  • 浏览: 3856 次
  • 性别: Icon_minigender_1
  • 来自: 上海
最近访客 更多访客>>
社区版块
存档分类
最新评论

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();
  }
 }

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics