图库一次滚动一张图像
如何使图库控件一次滚动一张图像?另外,制作这些图像的连续循环的好方法是什么?我尝试重写 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();
}
how to make a gallery control to scroll one image at a time? Also what is a good way of making a continuous loop of those images? I tried overriding onFling, does not work at all.
This moves image certain distance but does not really implement "true paging".
@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();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我创建了新的控件,将其命名为 CustomGallery 并从 Gallery 扩展了它。在自定义图库中,我放置了以下内容:
在我的活动中,我使用 CustomGallery 而不是图库。这有效。有一件事,我们从 2.2 升级到 2.3(姜饼)。之前当我尝试覆盖 onFling 时,它对我不起作用。所以我怀疑这也与操作系统的版本有关。
I created new control, called it CustomGallery and extended it from Gallery. In Custom Gallery I placed the following:
In my activity I am using CustomGallery instead of Gallery. This works. One thing, we moved from 2.2 to 2.3 (gingerbread). It didn't work for me before when I tried to override onFling. So I am suspecting this also have something to do with the version of OS.
Aniket Awati 的解决方案最适合我。不过,我建议进行改进,以避免在某些情况下滚动两个项目。
Aniket Awati's solution worked best for me. However I would suggest an improvement to avoid two items beings scrolled in certain cases.
这一直有效。对我来说所有版本都没有失败。
This works all the time. on all versions without fail for me.