且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android的 - 向左滑动|权利。手势检测

更新时间:2022-12-05 16:59:25


  

我不能只是说,
  使用按钮LinearLayouts是
  那些看着外面的刷卡
  手势?还是因为他们是隐藏
  上的按钮的背面,这不能
  怎么办?


块引用>

我认为这是precisely你要面对的,除非你发现所有的视觉对象刷卡的问题。

的多个按钮(或其他控件)在屏幕上,更准确的用户将不得不当他们开始/结束滑动手势 - 换句话说,他们就需要开始/结束无论是在你的按钮之间的空隙

要检测轻扫需要开始和结束的位置 - 如果用户开始和上按钮(没有被监听的滑动)结束然后轻扫不会被检测到。同样,在开始上的一个按钮,并在缺口结束(或者相反)将不会检测到有效刷卡或是因为只有开始/结束点之一是有效的刷卡检测。

我能想到的(虽然我从来没有尝试过我自己),***的方法是使用一个GestureOverlayView。这可以让你有你的背景视图(S)顶部的透明覆盖,可以用来检测之类的东西'刷卡'没有你的基本观点需要了解的手势。

看到这个开发者资源Gestures

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

Android - basic gesture detection

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

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