Android - 向左|向右滑动。手势检测

发布于 2024-10-27 16:55:49 字数 564 浏览 0 评论 0原文

试图将这个“手势”功能添加到我的第一个程序中,几乎我所做的每个搜索都来到这个线程:

网格布局上的滑动手势检测

我能够让它工作..但就我而言,我不确定它是否100%正确。

在我的布局中,我有 3 个水平的 LinearLayout,每个都有 5 个按钮.. 所以它是 3 列,每列 5 个按钮.. 根据我必须的线程:

“将手势侦听器附加到添加到主布局的所有视图; ”

这意味着对于所有 15 个按钮:

“button.setOnTouchListener(gestureListener);”

难道我不能说带有按钮的 LinearLayout 是负责滑动手势的吗?或者因为它们“隐藏”在按钮背面,所以无法做到这一点?

因为我有另一个布局,我想用它来实现,并且它有更多的按钮..

所以..只是寻找一种更简单的方法来检测屏幕上的向右滑动 |离开..如果确实存在..

提前谢谢你

was trying to add this "gesture" function to my first program, and almost every search I did came to this thread:

Fling gesture detection on grid layout

I was able to get it working.. but in my case, I am not sure if it's 100 % correct.

In my layout, I have 3 horizontal linearLayouts, each one has 5 buttons.. so it's 3 columns of 5 buttons.. according to the thread I had to:

"Attach your gesture listener to all the views you add to the main layout;"

that means for all the 15 buttons:

"button.setOnTouchListener(gestureListener);"

Couldn't I just say that the LinearLayouts with the buttons are the ones looking out for the swipe gestures? Or because they are "hidden" on the back of the buttons, this can't be done?

Because I have another layout I want to implement with this, and it has even more buttons..

So .. just looking for a simpler way of detecting on my screen for swipe right | left .. if it does exists..

Thank you in advance

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

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

发布评论

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

评论(1

疑心病 2024-11-03 16:55:49

我不能直接说
带有按钮的 LinearLayouts 是
那些寻找滑动的人
手势?或者因为它们是“隐藏的”
在按钮的背面,这不能
完成了吗?

我认为这正是您将面临的问题,除非您检测到所有视觉对象上的滑动。

屏幕上的按钮(或其他小部件)越多,用户在开始/结束滑动手势时必须越准确 - 换句话说,他们需要在按钮之间的间隙中开始/结束。

要检测滑动需要开始和结束位置 - 如果用户在按钮上开始和结束(不监听滑动),则不会检测到滑动。同样,从按钮开始并以“间隙”结束(反之亦然)也不会检测到有效的滑动,因为只有开始/结束点之一对于“滑动检测”有效。

我能想到的最好的方法(虽然我自己从未尝试过)是使用 GestureOverlayView。这允许您在背景视图之上有一个透明的覆盖层,并且可以用于检测“滑动”之类的内容,而无需您的底层视图了解手势。

请参阅开发人员资源手势

Couldn't I just say that the
LinearLayouts with the buttons are the
ones looking out for the swipe
gestures? Or because they are "hidden"
on the back of the buttons, this can't
be done?

I think that's precisely the problem you're going to face unless you detect the swipe on all visual objects.

The more buttons (or other widgets) on the screen, the more accurate a user will have to be when they start/end the swipe gesture - in other words they'd need to start/end both in gaps between your buttons.

To detect a swipe requires start and end locations - if the user starts and ends on buttons (which aren't listening for the swipe) then a swipe won't be detected. Similarly, starting on a button and ending in a 'gap' (or vice versa) won't detect a valid swipe either because only one of the start/end points is valid for 'swipe detection'.

The best approach I can think of (although I've never tried myself) is to use a GestureOverlayView. This allows you to have a transparent overlay on top of your background view(s) and can be used to detect things like 'swipe' without your underlying views needing to know about gestures.

See this in the developers resources Gestures

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