Android Gallery View 给定项目的 onClickListener 时出现滚动问题
我在我的应用程序中使用了图库。
因为我在每个画廊项目中有两个图像,如下所示
每个兔子和鼠标图像都组合为一个画廊项目。
因此,我为两个图像都提供了 onclickListener,但如果我这样提供,我将无法通过触摸这些图像来滚动...如果我删除该单个图像的 onClickListener,我就可以滚动。
如何存档每个图像的滚动和 onClick。
I have used gallery in my app.
In that i have two images in each gallery item like this
Each rabbit and mouse image is combined as a single gallery item.
So I give onclickListener for both images but if I give like that I can't scroll by touching those images... If I remove onClickListener for that individual images I am able to scroll.
How to archive both scroll and onClick for each images.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这回答了您的问题。您必须让您的活动同时处理 onClick 和手势。
This answers your question. You have to let your activity handle both onClick and Gestures.
就我而言,我只是使用 Gallery.setOnItemClickListener 和监听器来处理对父 Activity 的回调。
当我像上面的解决方案中那样监听 Activity 时,我没有注册点击。
In my case I just used the Gallery.setOnItemClickListener with the Listener handling the callback to the parent Activity.
When I had the Activity listening as in the the solution above the clicks didn't register for me.
我也面临这个问题。经过 2 天的工作,我找到了一个完美的解决方案:
onItemClickListener
。在activity上,监听gallery和activity的
onTouchEvent
,记下原始坐标<前><代码>@Override
公共布尔 onTouch(View v, MotionEvent 事件) {
x = (int)event.getRawX();
y = (int)event.getRawY();
返回假;
}
@覆盖
公共布尔onTouchEvent(MotionEvent事件){
x = (int)event.getRawX();
y = (int)event.getRawY();
返回 super.onTouchEvent(event);
}
onItemClick
,你会得到每个查看其内部并检查点击坐标。I faced to this problem too. And after 2 days working, I found a perfect solution for this:
onItemClickListener
for gallery too.On the activity, listen to
onTouchEvent
of gallery and activity, write down the raw coordinateonItemClick
for the gallery, you get each view inside it and check the click coordinate.我遇到了同样的问题,但很容易解决。我所做的是将 setOnItemClickListener 添加到 GalleryView,然后获取我想要的视图,在我的例子中是 TextView。
在您的情况下,您可以首先检查显示了哪些图像,然后根据该信息您可以操纵视图。希望这有帮助
I had this same problem but solved it pretty easy. What I did was is added setOnItemClickListener to the GalleryView and then grabbed the view that i wanted, which was in my case a TextView.
In your case you could first check which images are shown and based on that information you can maniuplate the view. Hope this helps
我的活动中有多个画廊,我这样做:
实现
OnItemClickListener
:重写
onItemClick()
方法I have multiple galleries in my activity and I do it that way:
Implementing the
OnItemClickListener
:Overriding
onItemClick()
method我的解决方案:
不要这样做!
:=)) (花了超过 6 个小时尝试解决这个问题...对我来说不起作用...)
使用了另一种方法(不同的布局)
My Solution:
don't do this!
:=)) (spend over 6 hours trying to solve this.. didnt work for me...)
used another Approach (different Layout)