Android Meditation Note (v): ListView Good Programming Guide

Source: Internet
Author: User

an important UI component that makes up Android apps is the ListView, which we use a lot in our project, so we summarize the following experience to share the discussion 1. Reuse the Convertview in the adapter GetView functioneach row of the list item is usually reusable, and reuse avoids creating multiple times so that scrollingmore smooth. (Note: The 2.3 system will be preserved when reusing view, such as the gone state, so reuse in GetView ConvertviewwhenTo re-set the visibility property)  2 . use Viewholder to save elements found through Findviewbyid usually we use Findviewbyid to find the TextView or button inside a layout and assign or manipulate it accordingly. in the ListView, because a large number of view is reusable, we can create a Viewholder class to save the found elements and then use the Settagset to Convertview. Reuse is just to use Gettag to get it. This avoids multiple lookups of wasted computing resources  3, the use of Relativelayout to replace the item in the hierarchy of too many linearlayoutUnder normal circumstances, LinearLayout layout will be convenient or even faster than relativelayout, but as the level of deepening the former speed will be more and more slow. This makes the list of multiple item more obvious, and we can use a layer of relativelayout to replace several levels of linearlayout in the layout to speed up the computation. 4, in the fast scrolling time for some more consumption of system resources of the action is not executedFor example, mobile phone QQ in the contact list can still be fast sliding slide, which to load a lot of images of the app is difficult to achieve, our project has encountered a similar lagproblem. Results using the same as the mobile phone QQ small strategy to solve the problem is simple, the key is the Avatarload only when scrolling is stopped
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.