Android:如何从图库中删除选择行为?

发布于 2024-12-06 18:43:47 字数 254 浏览 1 评论 0原文

我确实需要在我的应用程序中进行水平滚动,因此我覆盖了 Gallery,并尝试使用 OnItemSelectedListener 和我从在 Gallery 上设置的 OnTouchListener 调用的 GestureDetector 执行某些操作。我想要的是在滚动时删除图库项目的自动选择,但我希望能够单击一个项目来选择它。

如果我在适配器中填充的视图上设置 OnClick 侦听器,则图库无法滚动。此外,我在图库上设置的侦听器永远不会调用 OnItemClicked 事件。

I really need horizontal scrolling in my app, so I overrode Gallery and I'm trying to do something with an OnItemSelectedListener, and a GestureDetector I'm calling from an OnTouchListener I've set on the Gallery. What I want is to remove the auto-selection of Gallery items as I scroll, but I want to be able to click an item to select it.

If I set an OnClick listener on a view that is populated in the adapter, the Gallery fails to scroll. Also, the OnItemClicked event is never called for the listener I set for that on the Gallery.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

仅冇旳回忆 2024-12-13 18:43:47

要从所有项目中删除选择,您应该执行以下操作:

youGallery.setUnselectedAlpha(1);

To remove selection from all items you should do this:

youGallery.setUnselectedAlpha(1);
影子是时光的心 2024-12-13 18:43:47

也许我的答案这个问题将为您提供帮助。这是本来就不该实现的事情……

Maybe my answer to this question will help you. It's something which wasn't intended to be ever realized...

天气好吗我好吗 2024-12-13 18:43:47

对于您的情况,为什么不只使用 Horizo​​ntalScrollView 。只需在里面放置一个线性布局,并根据需要添加任意数量的图像视图(如果您使用图像),或者在 java 代码中动态添加它。

这将默认选择图库。这比尝试覆盖图库小部件默认方法更容易。

For your case why dont you just use a HorizontalScrollView. Just put a linear layout inside and add as many imageview's as you need if your using images, or dynamicaly add it in java code.

This will elemenate the selection of gallery by default. This will be easier than trying to Override the Gallery widget default methods.

黯然 2024-12-13 18:43:47

为什么不在图库中单击要选择的项目时设置一些标签。
现在,当您在选择项目后单击时,只需检查您设置的标签,然后根据条件您可以移动到新屏幕以及您想要执行的任何任务。

但请记住一件事,在构建图库视图时,您必须为每个图库项目设置标签。

我希望你能明白我想说的话。
如果您还有任何问题,请告诉我。
我遇到了同样的情况,我解决了。

Why not you set some tag while you click on an item in the Gallery to select.
Now once again when you click after the item is selected just check for the tag that you had set, and based on the condition you can move to new screen and whatever task you want to perform.

But keep one thing in mind, you have to set the tag with every gallery item while building the gallery view.

I hope you will get what I want to say.
If still you have any problem then let me know.
I had the same scenario and I solved that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文