Recyclerview implement drag-and-drop sort slip removal effect
Pre-stated:
Recyclerview is an upgraded version of the ListView that is more prescriptive than a ListView, and features and animations can be added by themselves, easily extended, and also inherit the benefits of the ListView multiplexing Convertview and Viewholder.
Thinking Analysis:
1, guide the package, use Recyclerview in the layout
2, need a JavaBean to store the display information
3, need a fill recyclerview layout file
4. Find Recyclerview in code and bind adapter and touch events for it
5, the adapter writing, touch event processing
In general, the same as the ListView, is to change a code style
Diagram of Ideas:
Effect one (linear layout):?????????????????????????????????????????????????????? Effect two (Grid layout):
? ?
Step one: Recyclerview is in Support.v7 pack, Android Studio is Recyclerview this package
Step Two: Create a layout file using Recyclerview
Step three: Create a JavaBean that stores the information for item
Step four: Create a Itemview layout
Step five: Create a Recycleview adapter
Thinking Analysis: the implementation of the form here is a bit different from the ListView, it inherits not the Baseadapter, inherits the Recycleview adapter, and the generic fills a viewholder, this viewholder in the class as the Inner class implementation , the other implementations are the same as the ListView.
Step six: Use in code
Unlike the ListView, this must be written here, otherwise the view does not appear, also this sentence can control the layout for the LinearLayout or the GridView or waterfall flow layout
Step Seven: Bind touch events for Recyclerview, here's where all the code we implemented
Thinking Analysis: We specify the drag and drop action is up and down, and delete effect is left and right delete. In the drag-and-drop event, it is through the collection of an exchange and then implement the layout of the update, here Recyclerview adapter to help us achieve good, easy to use, and delete the event is a collection delete a data, and then update the layout.
If you want to achieve the effect of two, you can make a similar desktop drag-and-drop sorting effect, this will be free to play it, to achieve the effect of two, as long as the effect on the basis of a modified two code can:
Of course, there is a waterfall flow effect, only in the effect of two on the basis of modifying a code can, if you want to achieve more complex effect, you can self-Baidu:
Source code is Androidstudio module, the proposed import module imports the source code download
Android Base Control--recyclerview implement drag-and-drop sort slip removal effect