Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Raw coordinates to ListView item

Tags:

android

I have the following problem. On my layout I have an action bar (which takes for example 150dp height) and the rest is 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?

like image 738
Alex Orlov Avatar asked Dec 12 '22 08:12

Alex Orlov


1 Answers

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.

like image 76
riotopsys Avatar answered Jan 08 '23 09:01

riotopsys