Android native provides and expands the listview:expandablelistview of the grouping, yet its UI capabilities are insufficient, such as no native animation expansion and support, compared to the UITableView provided by native iOS.
However, the optimization of performance is endless, when sub-view (Childview) within the group becomes complex, or the parent structure of the ListView is complex, such as embedding with other LinearLayout, framelayout, or ScrollView, And when the parent uses the custom overridden Onmeasure () method, the efficiency of generating childview greatly affects the performance of the application.
The key to rational use of animatedexpandablelistview is the realization of Animatedexpandablelistview#getrealchildview (), which is the responsibility of application development. In the actual project, by optimizing Getrealchildview (), the animation effect's start time was reduced from 1340ms to 680ms (expand a grouping with 5 sub-items). The location and solution of the problem found is based on the use of the method tracing provided by Android (android.os.Debug.startMethodTraceing) for analysis.
The Getrealchildview () implementation before optimization requires a lot of view initialization because there is no available convertview, and in fact, the childview generated during the animation drawing phase can be reused, convertview in time and given. As TraceView profile below sees, Getchildview () consumes more than a second before optimization.
Optimized performance:
How is this done? This requires us to look at the principle of animation unfolding, which is the most time-consuming action in Getchildview (). First of all, to exclude the effects of other factors, focusing on animatedexpandablelist, we use the native example provided on GitHub for analysis: This is the case of expanding the grouping of 5 sub-items, note the view generation of 5 sub-groups, Layoutinflater.inflate was executed 10 times, which was twice times as much. And inflate is quite time-consuming. Is there a way to reduce this part of the work consumption?
The method is to use the Android recommended LRU cache to save the Childview. For LRUCache, see Android Reference documents and training. It is particularly important to note that Childview needs to be regenerated when the dataset is changed, rather than in the cache, and the method used here is to determine the type of Childview. In your project, you need to carefully consider how the dataset changes to update the cache. The effect is as follows: The number of inflate is reduced to 5 times and is not wasted at one time. Consumption time reduced from 160ms to 80ms.
Android Expandablelistview animation spread effect and performance optimization using TraceView