简体   繁体   English

如何实现Android listview打开手势

[英]How to implement Android listview opening gesture

This is an open question about Android ListViews, Gestures and Animations. 这是关于Android ListViews,Gestures和Animations的一个开放性问题。 I'm really not familiar with the gestures in Android, so I'm just looking for ideas and grey matter on this. 我真的不熟悉Android中的手势,所以我只是在寻找想法和灰色内容。

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 . 截图来自此处的iOS开源项目。

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 ? 问题是,你将如何实现像我在iPhone / iPad应用程序中越来越常见的“listview开放”手势,但对于Android?

Edit 1, idea 1: 编辑1,想法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? 好的第一个想法,AFAIK的Pinch手势有点像拖动手势,所以我想我们可以在屏幕上获得两个手指的X和Y坐标?

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 使用getChildAt 函数从第一个索引迭代到最后一个索引

For each child, call the getLocationOnScreen method to get coordinates of the current iterated item 对于每个子节点,调用getLocationOnScreen 方法以获取当前迭代项的坐标

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(?). 性能考虑appart我认为它可以工作,但也许有一个更简单的方法来获得这两个项目(?)。

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. 感谢小费@rhlnair,我借此机会告诉大家我在业余时间开始研究这个问题,欢迎您随时为此提供帮助。

The project is at https://github.com/arnaudbos/Android-GestureListView . 该项目位于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. 我在分支“尝试通过比例 - 手势检测器”中有一些非常令人鼓舞的东西,但是ListView有一些副作用。

Come on folks! 来吧伙计们!

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 https://github.com/commonsguy/cwac-touchlist

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 请参阅底部使用比例监听器的部分: 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. 如果比例高于(您正在“缩放”)阈值,则创建一个新元素并让视图从列表适配器重新填充。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM