跨多个滚动视图处理触摸事件

发布于 2024-12-27 20:05:56 字数 166 浏览 0 评论 0原文

我有两个并排的滚动视图,我希望用户能够从左到右滚动视图来回拖动列表项。但是,我找不到处理触摸事件的方法。我无法为每个滚动视图单独设置触摸监听器,因为从一个滚动视图传递到另一个滚动视图时拖动手势会被丢弃。我尝试在两者的顶部创建一个绝对布局,它从拖放角度工作,但它阻止我滚动滚动视图。有一个简单的解决方案吗?有人能帮我吗?

I have two scrollviews side by side, I want the user to be able to drag list items back and forth from left to right scrollviews. However, I can't find a way to handle the touch events. I can't set a touch listener for each scrollview seperately as the drag gesture gets dropped when passing from one to another. I tried creating an absolute layout over the top of both, which works from the drag and drop perspective, but it stops me from being able to scroll the scrollviews. Is there a simple solution to this? can anyone help me out?

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

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

发布评论

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

评论(1

行至春深 2025-01-03 20:05:56

一般来说,onTouchListener 返回一个 boolean 来指示触摸是否已被处理。由您决定是否处理触摸。当用户触摸View时,Android将调用它的触摸监听器。如果触摸监听器返回true,则它将认为触摸已被处理,然后继续。如果触摸监听器返回 false,那么它将向上移动到父视图(在这种情况下,无论您的 ScrollView 是什么)。然后调用父视图的触摸侦听器,并且必须决定如何处理触摸。它将继续级联父视图,直到返回 true 或到达末尾。

在您的情况下,您可能必须决定用户必须做什么才能拖动和拖动。下降与滚动。也许用户必须长按某个项目才能拖动它或执行其他操作。

Generally, onTouchListener returns a boolean that indicates whether the touch has been handled. It's up to you to decide whether the touch was handled or not. When the user touches a View, Android will call it's touch listener. If the touch listener returns true, then it regards the touch as handled then moves on. If the touch listener returns false, then it will go up one to the parent view (in this case whatever your ScrollView is). Then the parent view's touch listener is called and must decide how to handle the touch. It will keep cascading up the parent views until a true is returned or until it reaches the end.

In your case, you may have to decide what the user has to do in order to drag & drop vs. scrolling. Perhaps the user must do a long press on an item before he/she can drag it or something.

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