如何使图库控件一次滚动一张图像?另外,制作这些图像的连续循环的好方法是什么?我尝试重写 onFling,根本不起作用。
这将图像移动一定的距离,但并没有真正实现“真正的分页”。
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
// return super.onFling(e1, e2, velocityX, 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();
}
我创建了新的控件,将其命名为 CustomGallery 并从 Gallery 扩展了它。在自定义图库中我放置了以下内容:
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
return super.onFling(e1, e2, 0, velocityY);
}
在我的活动中,我使用 CustomGallery 而不是 Gallery。这有效。有一件事,我们从 2.2 升级到 2.3(姜饼)。之前当我尝试覆盖 onFling 时,它对我不起作用。所以我怀疑这也与操作系统的版本有关。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)