I am trying to implement drag and drop on a GridView in android (ICS), but when I drag the item to the edge of the screen, the GridView doesn’t scroll. How can I implement this functionality?
I am trying to implement drag and drop on a GridView in android (ICS),
Share
First of all if you don’t need to support android 2.x ( API <11 ) this Andorid Drag and Drop tutorial is what you are looking for. I’ve never tried that way cause i had to implement it on 2.x but i took a look at it seems pretty straight forward.
To implement the autoscroll i guess you could use ACTION_DRAG_EXITED or ACTION_DRAG_LOCATION on the grid view and fire the scroll manually when you see that the location is next to the view bounds.
If you instead have to implement it on 2.x then it’s going to be much more hard, you basically need to implement all the DRAG events, or a subset of them, by yourself.
I did in once with a ListView and what you have to do is:
Enable the drawing cache on the GridView items( setDrawingCacheEnabled ) and use getDrawingCache() to copy the bitmap of the view on DRAG_START.
Than what you have to do is to use that bitmap drawn on top of the GridView at the position that the ACTION_MOVE event gives you.
it’s not easy but if you take your time you can manage to get it.
what more, I haven’t check today but maybe you can try to google a bit an see if someone took the time to implement it and release it Open Source.