A ListView with an internal complex layout is used in the project, and each item has a dynamic child item, which is the same as the ListView style in the ListView item. The idea is to start with a ListView, and then add a linearlayout in the item, and then the code dynamic Generation sub Item view added in it, I hope that the expression we can understand, according to the idea of doing well after the discovery of fast sliding, a card a meal, Can not look directly, in the configuration of low-point machine is not even see.
But because of the progress has not been optimized, now look back, although it has been used Viewholder but the listview buffer mechanism is not functioning at all, because each item show needs to removeall the child item, and then add again, drawing time too long, caused the lag.
How do you solve this problem, Nikki?
just good Google in Support V7 launched the Recyclerview, has a better cache optimization mechanism, I like the Savior, hurriedly the ListView replaced with Recyclerview, but the effect is not satisfactory, not my imagination of efficiency improvement, think carefully, Recycleview is only optimized for the multi-type case of the ListView, and the actual requirement is to generate the item dynamically in item, without the advantage of Recyclerview.
So naturally the next thing to think about is to kill the dynamically generated item section and split the data into a single ListView item. But also worry that this workload will not be very large, the actual abstraction process found very easy, the original model data was split into 7 different types of Model,getview when the first to get the type of the current model by postion, and then return the different view item , it is simple to split a ListView with only one item into a ListView with 7 types of item. After running, the speed of the rushing, the feeling is more an item of the same.
The ListView supports multiple types of item when there is a pit: The following two methods must be replicated when inheriting Baseadapter
When sliding the ListView, after the first item disappears, the item type entering the screen must pass <span style= "font-family:arial, Helvetica, Sans-serif;" The >getitemviewtype conforms to the type before it is reused, otherwise a new item type is created, of course, if you have to use the ListView cache tag</span>
@Override public int getitemviewtype (int position) { return super.getitemviewtype (position); } By default this method returns 1, and there are several types that must tell Listview,listview to create several different types of queues @Override public int Getviewtypecount () { return Super.getviewtypecount (); }
This time, since the dynamic generation of sub-item mechanism has been eliminated, I thought of Recyclerview, if usingwill recyclerview be better than a ListView? Say dry, 10 minutes I have completed the replacement (thinking that I moved the efficiency of the brick or very fast), after running up, sure enough swish (in fact, the naked eye has been difficult to distinguish it from the ListView and the Difference). But follow Google should not be wrong, he said:
theRecyclerView
Widget is a more advanced and flexible version ofListView
. This widget was a container for displaying large data sets so can be scrolled very efficiently by maintaining a limited n Umber of views. Use theRecyclerView
Widget when you have data collections whose elements change at runtime based on user action or network events.
Hope to help the students with similar needs:
There are complex layouts in the ListView, especially with the child layouts of dynamically generated layouts, consider splitting the original item into different types and then using Recyclerview.
The ListView optimization idea of Android complex layout