1. Using Recyclerview
The Recyclerview can be used to easily animate the image when switching, which is better than the GridView.
2. Drag and drop implementation
Inherit the View.ondraglistener, operate on the drag process,
Action_drag_started gets the item to the action
The action_drag_location determines whether the position of the item is exchanged based on the position of each stop.
Action_drag_ended and new location
Abstract class, add Onitemtouchlistener and Onscrolllistener for Recyclerview, record Ontouch item, and determine if Recyclerview can scroll during drag and drop. This lets you scroll through the Recyclerview when the dragged item is fast to the boundary, allowing you to swap positions with item that would otherwise be invisible on the screen.
Viewholder Implementing the StartDrag method
2.itemDecoration
To add divider to Recyclerview item, there are two ways to override the OnDraw method to draw Itemdivider, or to override the Getitemoffsets method so that item can be separated.
3.GridlayoutManager
When the Recyclerview is embedded in the ScrollView, a carbon layoutmanager is required, where the Onmeasure method is replicated, and the height or width of each item needs to be calculated to overlay, when the Recyclerview item is many , do not use this way, back to cause view can not be reused, which in the calculation item height, need to add each item's itemoffsets, view Recyclerview source discovery, unable to get directly to the item offsets, Finally, it takes reflection to get its value:
try {method = Recyclerview.getclass (). Getdeclaredmethod ("Getitemdecorinsetsforchild", View.class); Method.setaccessible (TRUE); Final Rect insets = (rect) method.invoke (Recyclerview, child); Itemdecorationheight = heightused + insets.height (); Itemdecorationwidth = widthused + Insets.width ();} catch (Nosuchmethodexception e) {log.d ("Fullgridlayoutmanager", "no Method found"); catch (Illegalaccessexception e) {log.d ("Fullgridlayoutmanager", "illegalaccessexception");} catch (InvocationTargetException e) {log.d ("Fullgridlayoutmanager", "invocationtargetexception");}
Android implementation picture selection drag and drop control