如何在父视图(ScrollView)中处理子视图(CustomView)的触摸事件?
在我的应用程序中,我使用 ScrollView
滚动 ImageView
,并且我将动态添加一个自定义视图到 ImageView< 的
ScrollView
覆盖层/code>,我有自定义视图的 onTouch
事件。添加到滚动视图后,我无法使用自定义视图的触摸侦听器,滚动视图仍在处理该问题。
如何停止滚动视图触摸侦听器,以及如何启用我们的自定义视图触摸侦听器。
In my app i am using ScrollView
for scrolling the ImageView
, and i will add one customview dynamically to that ScrollView
overlay of ImageView
, i have onTouch
events for customview. after adding to the scroll view i am not able to use the touch listeners of customview, still scrollview was working on that.
how to stop the scrollview touch listeners, and how to enable our custom view touch listeners..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议你不要使用
ScrollView
。只需在LinearLayout
中添加自定义视图并实现OnGestureListener
,然后使用GestureDetector
您就可以监听所有事件(例如 onDown()、onFling( )、onScroll()、onSingleTapUp()、onDown() 等)。您可以感知滚动幅度,然后使用scrollBy()
方法可以滚动图像(自定义视图)。更多详细信息可以参考以下帖子:Android 中的平滑滚动
I suggest you not to go with
ScrollView
. Simply add your custom view inLinearLayout
and implementOnGestureListener
and then usingGestureDetector
you can able to listen all events(like onDown(),onFling(),onScroll(),onSingleTapUp(),onDown(),etc). You can sense scroll magnitudes and then by usingscrollBy()
method you can scroll your image(custom view). For more detilas you can refer following posts:Smooth scrolling in Android