2013年4月23日 星期二

[Android] Gallery Scroll One Image At A Time


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public class ScrollOneImageAtATimeGallery extends Gallery {

 public ScrollOneImageAtATimeGallery(Context context) {
  super(context);
 }

 public ScrollOneImageAtATimeGallery(Context context, AttributeSet attrs) {
  super(context, attrs);
 }

 public ScrollOneImageAtATimeGallery(Context context, AttributeSet attrs,
   int defStyle) {
  super(context, attrs, defStyle);
 }

 private boolean isScrollingLeft(MotionEvent e1, MotionEvent e2) {
  return e2.getX() > e1.getX();
 }

 @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;
 }
}

沒有留言:

張貼留言