gpt4 book ai didi

android - 图库一次滚动一张图片

转载 作者:行者123 更新时间:2023-11-29 14:18:57 27 4
gpt4 key购买 nike

如何让图库控件一次滚动一张图片?另外,使这些图像连续循环的好方法是什么?我尝试覆盖 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);
}

在我的 Activity 中,我使用 CustomGallery 而不是 Gallery。这行得通。一件事,我们从 2.2 移动到 2.3( Gingerbread )。在我尝试覆盖 onFling 之前它对我不起作用。所以我怀疑这也与操作系统版本有关。

关于android - 图库一次滚动一张图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4687370/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com