Still using the Lisview? Recyclerview have been out for more than a year!
Presumably we have more or less contact or understand recyclerview, why not used up, the reason is probably as follows?
- ListView I use very good, why should change Recyclerview?
- ListView Stable, familiar, but also know a lot of open-source library, particularly useful!
- Recyclerview can't add head, ListView can!
Recyclerview
In Andorid 5.0 came out soon, I have written a brief introduction of Recyclerview and basic use, do not know can look at the ListView upgrade version of Recyclerview, learned that the classmate can be ignored, and look down.
- Recyclerview The biggest advantage is the flexibility, Recyclerview just change a line of code can change a number of different layouts display layout, this is very convenient for developers!
- Recyclerview.adapter, a better package than Baseadapter, the Baseadapter GetView method is split into Oncreateviewholder method and Onbindviewholder method, forcing the need to create Viewholde R, the advantage is to avoid the beginner write poor performance code
What problems do we encounter in combat?
Get to the following skills will be able to use the Rcyclerview on the road unimpeded!
- Add Split Line
- Add a point by effect
- List animations
- Change a data hold current position
- Add Head Tail
- List grouping
- Various Effects integrated Demo
- More flexible Recyclerview
Add Split Line
//通过以下方法添加分割线mRecyclerView.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.VERTICAL_LIST));
Divideritemdecoration need to inherit recyclerview.itemdecoration this abstract class to implement some methods. But I feel too much trouble, so I think of:
Directly inside the bottom of the Item_view to add a line layout, so that there is no need to rewrite, and so there is a good thing is that if the careful classmate will find, add the split line, the last item below will not have a split line, obviously when the amount of data is not enough for a screen when it seems very abrupt, but in item_ A layout that adds a line below the view does not occur
Add a point by effect
Recyclerview directly inside the Item_view configuration can be selector.
Animation
A good user experience is to have an animated transition instead of a stiff refresh list.
Recommend a Recyclerview animation library (recyclerview-animators)
Write a picture description here
Recyclerview Add, remove animations, and the ListView needs to add additional code to implement.
Delete the notifyitemremoved of the adapter that called Recyclerview
Add notifyiteminserted to call Recyclerview's adapter
Speaking of adapter, let's just say that Recyclerview.adapter and Baseadapter offer these methods in an extra way:
The data has changed, so call this method and pass in the location of the change object.PublicFinalvoidNotifyitemchanged(int position);You can refresh the item that starts ItemCount quantity from PositionstartPublicFinalvoidNotifyitemrangechanged(int Positionstart,int itemCount);Add, the location of the incoming object.PublicFinalvoidnotifyiteminserted(int position);Delete, the location of the incoming object.PublicFinalvoidNotifyitemremoved(int position);Object moved from Fromposition to TopositionPublicFinalvoid notifyitemmoved (int fromposition, int toposition); //bulk Add public final void notifyitemrangeinserted (int Positionstart, int itemCount); //bulk Delete public Final void notifyitemrangeremoved ( int Positionstart, int itemCount);
Change a layout state of a list and keep the current position
This requirement is universal, that is, change the list of one item data, and then refresh the list, if it is a ListView refresh will return to the top, and recyclerview the same operation but the original sliding position unchanged.
The Recyclerview of various solutions adapter
Baserecyclerviewadapterhelper
Recyclerview with more flexible effect display layout
Twoway-view encapsulates Recyclerview common methods, such as Click and more, and supports more different layouts, making recyclerview easier to use!
Write a picture description here
Build It Up! Little Friends!
Wen/Chen Yuming (Jane book author)
Original link: http://www.jianshu.com/p/a92955be0a3e
Copyright belongs to the author, please contact the author to obtain authorization, and Mark "book author".
Still using the ListView?