如何实现Android listview打开手势
这是一个关于 Android ListViews、手势和动画的悬而未决的问题。 我真的不熟悉Android中的手势,所以我只是在寻找关于这方面的想法和灰质。
这是两个屏幕截图和视频示例,说明了对我的影响我正在努力思考。考虑一下看一下视频,这真的很值得。
屏幕截图来自 此处 的 iOS 开源项目。
问题是,如何实现“列表视图打开”手势,就像我在 iPhone/iPad 应用程序中越来越常见的手势,但对于 Android 来说?
编辑 1,想法 1:
好吧,第一个想法,据我所知,捏合手势在某种程度上类似于拖动手势,所以我想我们可以获得两个手指的 X 和 Y 坐标在屏幕上?
接下来,这个问题的答案可能会有所帮助,基本思想是:
获取列表中第一个可见项的索引位置
获取列表中最后一个可见项的索引位置
使用 getChildAt 函数从第一个索引迭代到最后一个索引
对于每个子项,调用 getLocationOnScreen方法来获取当前迭代项的坐标
之后,可能会在循环内完成捏合手势坐标和每个项目坐标之间的一些比较,以获取必须在其间插入新行的两个项目。
性能考虑因素我认为它可以工作,但也许有一种更简单的方法来获取这两个项目(?)。
下一个是谁? :)
更新:
感谢 @rhlnair 的提示,我借此机会告诉大家,我在业余时间开始从事这方面的工作,非常欢迎您加入对此提供帮助。
该项目位于 https://github.com/arnaudbos/Android-GestureListView。我在两个不同的分支上开始了两种不同的实现,并且希望任何人创建一个新分支。
我在“attemp-via-scale-gesture- detector”分支中有一些非常令人鼓舞的东西,但 ListView 产生了一些副作用。
来吧,伙计们!
This is an open question about Android ListViews, Gestures and Animations.
I'm really not familiar with the gestures in Android, so I'm just looking for ideas and grey matter on this.
Here's two screenshot and a video examples of the effect on what I'm trying to cogitate. Consider taking a look at the video, it's really worth it.
The screenshots are from an iOS open source project found here.
The question is, how would you implement a "listview opening" gesture like the one I see more and more often in iPhone/iPad apps, but for Android ?
Edit 1, idea 1:
Okay first idea, AFAIK the Pinch gesture is somehow like a dragging gesture, so I guess we can get the X and Y coordinates of the two fingers on the screen?
Next, the answer to this question may help, the basic idea is:
Get the index position of the first visible item in the list
Get the index position of the last visible item in the list
Iterate from the first index to the last with the getChildAt function
For each child, call the getLocationOnScreen method to get coordinates of the current iterated item
After that, some comparison between the pinch gesture coordinates and each item coordinates might be done inside the loop to get the two items between which the new row must me inserted.
Performances considerations appart I think it could work, but maybe there's a simpler way to get those two items(?).
Who's next? :)
Update:
Thanks for the tip @rhlnair, I take this occasion to tell everybody that I started to work on this on my spare time and you are more then welcome to help on this.
The project is at https://github.com/arnaudbos/Android-GestureListView. I started two different implementations on two different branches, and would enjoy anybody to create a new branch.
I have something really encouraging in branch "attemp-via-scale-gesture-detector" but some side effects from the ListView.
Come on folks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
似乎是一个具有挑战性的想法..
我认为清除应用程序中的一些效果(例如向上/向下拖动选定的行)可以从
https://github.com/commonsguy/cwac-touchlist
seems to be a challenging idea..
i think some of the effect in clear app like dragging a selected row up/down can be taken from
https://github.com/commonsguy/cwac-touchlist
当执行捏合手势时,您有两个手指放在屏幕上,因此有一个点位于这两点的中间。这是找到中间点的简单欧几里得算术。
然后按照您所说的在列表中找到该点位于上面的元素。你提到了性能,我认为这不会成为问题。您迭代循环几次并询问坐标。我在触摸事件上做得更糟。
如果捏合点位于列表项中间上方,则您将在上方创建项目,反之亦然。
请参阅底部使用音阶侦听器的部分:
http://android-developers.blogspot.com/2010 /06/making-sense-of-multitouch.html
使用比例侦听器,您可以使用比例来确定是否创建了新元素。如果比例高于(“缩小”)阈值,则创建一个新元素并让视图从列表适配器重新填充。
When doing a pinch gesture you have two fingers on the screen and therefore a point in the middle of those two points. That is simple euclidean arithmetic to find that middle point.
Then find as you say the element in the list that this point is above. You mention performance and I do not think this will be a problem. You are iteration a loop a few times and asking for coordinates. I have done much worse on touch events.
If the point between the pinch is above the middle of the list item you create the item above, and vice versa below.
See the section at the bottom where they use a scale listener:
http://android-developers.blogspot.com/2010/06/making-sense-of-multitouch.html
Using the scale listener you can use the scale to find out if you create a new element. If the scale is above (you are "zooming" out) a threshold you create a new element and let the view repopulate from the list adapter.