如何在父视图(ScrollView)中处理子视图(CustomView)的触摸事件?

发布于 2024-12-04 04:24:24 字数 267 浏览 5 评论 0原文

在我的应用程序中,我使用 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 技术交流群。

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

发布评论

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

评论(1

娇纵 2024-12-11 04:24:24

我建议你不要使用 ScrollView。只需在 LinearLayout 中添加自定义视图并实现 OnGestureListener,然后使用 GestureDetector 您就可以监听所有事件(例如 onDown()、onFling( )、onScroll()、onSingleTapUp()、onDown() 等)。您可以感知滚动幅度,然后使用 scrollBy() 方法可以滚动图像(自定义视图)。更多详细信息可以参考以下帖子:
Android 中的平滑滚动

I suggest you not to go with ScrollView. Simply add your custom view in LinearLayout and implement OnGestureListener and then using GestureDetector you can able to listen all events(like onDown(),onFling(),onScroll(),onSingleTapUp(),onDown(),etc). You can sense scroll magnitudes and then by using scrollBy() method you can scroll your image(custom view). For more detilas you can refer following posts:
Smooth scrolling in Android

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