原始坐标ListView项坐标、原始、ListView

2023-09-07 13:29:41 作者:把你的爱扔进海里

我有以下问题。 在我的布局,我有一个操作栏(这需要例如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?

推荐答案

是:getChildAt会给你列表中的任何项目的个人看法。 getLocationOnScreen给人一种观点的原始屏幕坐标。 的getWidth 和的的getHeight 将建立你的边框。 getFirstVisiblePosition和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.