Detailed explanation of common optimization methods for Android listview
Optimization of listview
Listview is one of the most commonly used components in layout and is very convenient to use. Let's introduce two common optimization methods
1. Item reuse optimization
See the figure below for details:
Summary: through the understanding of the above figure, we know that listview items can be reused. What can be reused? Android has defined a method for us. The convertview in getview (final int position, view convertview, ViewGroup parent) is specially used to handle reused items, so we just need to deal with it
2. Optimize findviewbyid
The system searches for child IDs from left to right, just like the tree mode
Every time you look for a child, it consumes a lot of resources, but the child's ID is created,
That is to say, they are fixed, even so, so we can optimize them;
The mode of finding r.id in the system is shown in the figure below:
Summary: through the understanding of the above figure, we know that the bottom operation of findviewbyid (ID) is too time-consuming. If there are more than 100 layers in a layout, I will look for a small 'ImageView' for half a day. Fortunately, at the Google IO conference in 2009, Google engineers introduced an optimized method by customizing a viewholder class, To bind the ID of the view, so as to reduce the time-consuming operation of system search
The actual codes of the two optimization schemes are as follows:
Thank you for reading, hope to help you, thank you for your support to this site!