我开发了一个自定义的 gallery,然后重写了 on-fling方法,每次刷新一个图像。能运行,但是现在的问题是当我从上到下刷新或者从下到上时,图像就刷新了,因此也改变了。
public class mygallery extends Gallery {
public mygallery(Context ctx, AttributeSet attrSet) {
super(ctx, attrSet);
}
private boolean isScrollingLeft(MotionEvent e1, MotionEvent e2) {
return e2.getX() > e1.getX();
}
private boolean isScrollingRight(MotionEvent e1, MotionEvent e2){
return e2.getX() < e1.getX();
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
int kEvent=0;
if (isScrollingLeft(e1, e2)) { // Check if scrolling left
kEvent = KeyEvent.KEYCODE_DPAD_LEFT;
} else if(isScrollingRight(e1, e2)) { // Otherwise scrolling right
kEvent = KeyEvent.KEYCODE_DPAD_RIGHT;
}
onKeyDown(kEvent, null);
return true;
}
}
要怎么做才能当我从上到下刷新或者从下到上时,图像不改变?