原始坐标ListView项 [英] Raw coordinates to ListView item

查看:107
本文介绍了原始坐标ListView项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题。 在我的布局,我有一个操作栏(这需要例如150dp高度),剩下的就是ListView控件。

I have the following problem. On my layout I have an action bar (which takes for example 150dp height) and the rest is ListView.

我能够抓住从操作栏中的一些看法,并将其拖到列表视图。 拖动通过windowsmanager实现。所以拖动时我正在rawY坐标。现在,我想匹配rawY与ListView的相对坐标,所以我想知道上面是什么项目的ListView中,我目前徘徊。

I'm able to grab some view from action bar and drag it onto listview. Dragging is implemented through windowsmanager. So when dragging I am getting rawY coordinates. Now, I want to match rawY with ListView relative coordinates, so I would know above what item in ListView I'm currently hovering.

是否有可能做到这一点?

Is there any possibility to do this?

推荐答案

是:<一href="http://developer.android.com/reference/android/view/ViewGroup.html#getChildAt%28int%29">getChildAt会给你列表中的任何项目的个人看法。 <一href="http://developer.android.com/reference/android/view/View.html#getLocationOnScreen%28int%5B%5D%29">getLocationOnScreen给人一种观点的原始屏幕坐标。 的getWidth 和的的getHeight 将建立你的边框。 <一href="http://developer.android.com/reference/android/widget/AdapterView.html#getFirstVisiblePosition%28%29">getFirstVisiblePosition和<一href="http://developer.android.com/reference/android/widget/AdapterView.html#getLastVisiblePosition%28%29">getLastVisiblePosition建立索引列表中进行搜索。

Yes: getChildAt will give you the individual view of any item in the list. getLocationOnScreen gives raw screen coordinates of a view. getWidth and getHeight will establish your bounding box. getFirstVisiblePosition and getLastVisiblePosition establish indexes in the list to search within.

这篇关于原始坐标ListView项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆