<span id="Label3"></p><p><p><span style="white-space:pre"></span><span style="font-family:SimSun; font-size:14px"><strong>I believe everyone will use the ListView control a lot of times, because it is really a lot of use, but there is a lot of wood has encountered too much data, when the slide to the ListView sometimes, it will need us to optimize it.</strong></span></p></p><p><p><span style="font-family:SimSun; font-size:14px"><strong><br></strong></span></p></p><p><p><span style="font-family:SimSun; font-size:14px"><strong>The ListView optimization mainly has the following aspects:</strong></span></p></p><p><p><span style="font-family:SimSun; font-size:14px"><strong>1, Convertview Reuse</strong></span></p></p><p><p><span style="font-family:SimSun; font-size:14px"><strong>2, Viewholder Sub-view Multiplexing</strong></span></p></p><p><p><span style="font-family:SimSun; font-size:14px"><strong>3. Cache Data Reuse</strong></span></p></p><p><p><span style="font-family:KaiTi_GB2312; font-size:14px"><br></span></p></p><p><p><span style="font-family:SimSun; font-size:18px"><strong>first, Convertview Reuse</strong></span></p></p><p><span style="font-family:KaiTi_GB2312; font-size:14px"><strong><span style="color:rgb(51,51,51); font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif; line-height:21px">First of all, the <span style="color:rgb(51,51,51); font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif; line-height:21px">listview principle: Each item in the ListView requires adapter to call a GetView () method, which passes a convertview parameter. The view returned by this method is the view shown in this Item. </span></span><span style="margin:0px; padding:0px; font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif; line-height:21px; color:rgb(255,0,0)"><span style="margin:0px; padding:0px; font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif; line-height:21px; color:rgb(255,0,0)">if the number of item is large enough to create a view object for each item, it will take up a lot of memory space, that is, create the View object (minflater.inflate (r.layout.lv_item, null); Generating a view from xml, which is an IO operation, is a time-consuming operation that will inevitably affect performance. </span></span><span style="color:rgb(51,51,51); font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif; line-height:21px"><span style="color:rgb(51,51,51); font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif; line-height:21px">Android provides a call</span></span><span style="margin:0px; padding:0px; font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif; line-height:21px; color:rgb(0,0,255)"><span style="margin:0px; padding:0px; font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif; line-height:21px; color:rgb(0,0,255)"><span style="margin:0px; padding:0px">recycler (repeated cycles)</span></span></span><span style="color:rgb(51,51,51); font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif; line-height:21px"><span style="color:rgb(51,51,51); font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif; line-height:21px">widget, which is when the ListView item is scrolled out of the screen view, the corresponding item view is cached in the recycler, which will be generated from an item, The Convertview parameter in the GetView that is called at this point is the view that scrolls out of the Screen's cached item, so if you can reuse this convertview, it will greatly improve performance. </span></span><br></strong></span></p><p><p><span style="font-family:KaiTi_GB2312; font-size:14px"><strong><span style="color:rgb(51,51,51); font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif; line-height:21px">so, How do we reuse it? Post Code:</span></strong></span></p></p><p><p><span style="font-family:KaiTi_GB2312; font-size:18px"><strong><span style="color:rgb(51,51,51); font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif; font-size:14px; line-height:21px"><br></span></strong></span></p></p><p><p><span style="font-family:KaiTi_GB2312; font-size:18px"><strong><span style="color:rgb(51,51,51); font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif; font-size:14px; line-height:21px">, when this convertview does not exist, that is, for the first time, we create a View object with the item layout and assign it to convertview, and later when we use <span style="font-family:KaiTi_GB2312"><span style="color:rgb(51,51,51); font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif; line-height:21px"><span style="font-size:14px">convertview, Just remove the Gettag from the Convertview and</span></span></span> you don't need to create the Item's layout object again, which improves performance.</span></strong></span></p></p><p><p><span style="font-family:KaiTi_GB2312"><strong><span style="color:rgb(51,51,51); font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif; line-height:21px"><span style="font-size:14px">second, Use Viewholder Reuse</span></span></strong></span></p></p><p><span style="font-family:KaiTi_GB2312"><strong><span style="color:rgb(51,51,51); font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif; line-height:21px"><span style="color:rgb(51,51,51); font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif; line-height:21px"><span style="font-size:14px">We all know the operation in the GetView () method is this: first create the View object from the XML (inflate operation, we use the reuse Convertview method optimization), and then in this view to findviewbyid, Find the control object for each child view of item, such as: ImageView, textview, and so On. Here the Findviewbyid operation is a tree lookup process, is also a time-consuming operation, so it also needs to be optimized, is to use viewholder, each Item's child view control object is placed in holder, when the first time the Convertview object is created , the Child view Control object of these item Findviewbyid is instantiated and saved to the Viewholder Object.<span style="font-family:KaiTi_GB2312; font-size:18px"><span style="font-family:kaiti_gb2312; font-size:18px"><span style="color:rgb (51,51,51); font-family:Georgia, ' Times New Roman ', ' bitstream Charter ', times,serif; font-size:14px; line-height:21px "><span style=" font-family:kaiti_gb2312; font-size:18px "><span style=" font-family:Georgia, ' Times New Roman ', ' bitstream Charter ', times,serif; font-size:14px "><span style=" font-family:kaiti_gb2312 "><span style=" font-family:georgia, ' times New Roman ', ' Bitstream Charter ', times,serif "><span style=" font-family:kaiti_gb2312 "><span style=" font-family:georgia, ' Times New Roman ', ' bitstream Charter ', times,serif ' > Then Convertview object is set to tag with Settag viewholder, When you load the ListView item later, You can remove the multiplexed Viewholder object directly from the tag, no more <span style= " font-family:kaiti_gb2312"><span style="color: RGB (51,51,51); font-family:georgia, ' Times New Roman ', ' bitstream Charter ', times,serif; line-height:21px "><span style=" font-size:14px ">findviewbyid to find the child control object for Item. This greatly improves Performance. </span></span></span></span></span></span></span></span></span></span></span></span></span><br></span></strong></span></p><p><span style="font-family:KaiTi_GB2312"><strong><span style="color:rgb(51,51,51); font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif; line-height:21px"><span style="color:rgb(51,51,51); font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif; line-height:21px"><span style="font-size:14px"><span style="font-size:14px"><span style="font-family:KaiTi_GB2312; font-size:18px"><span style="color:rgb(51,51,51); font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif; font-size:14px; line-height:21px"><span style="font-family:KaiTi_GB2312; font-size:18px"><span style="font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif; font-size:14px"><span style="font-family:KaiTi_GB2312"><span style="font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif"><span style="font-family:KaiTi_GB2312"><span style="font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif"><span style="font-family:KaiTi_GB2312"><span style="color:rgb(51,51,51); font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif; line-height:21px"><span style="font-size:14px">put in a complete code:</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></strong></span></p><p><span style="font-family:KaiTi_GB2312"><strong><span style="color:rgb(51,51,51); font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif; line-height:21px"><span style="color:rgb(51,51,51); font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif; line-height:21px"><span style="font-size:14px"><span style="font-size:14px"><span style="font-family:kaiti_gb2312; font-size:18px"><span style="color:rgb ( 51,51,51); font-family:georgia, ' Times New Roman ', ' bitstream Charter ', times,serif; font-size:14px; line-height:21px "><span style=" font-family:kaiti_gb2312; font-size:18px "><span style=" font-family:Georgia, ' Times New Roman ', ' bitstream Charter ', times,serif; font-size:14px "><span style=" font-family:kaiti_gb2312 "><span style=" font-family:georgia, ' times New Roman ', ' Bitstream Charter ', times,serif "><span style=" font-family:kaiti_gb2312 "><span style=" font-family:georgia, ' Times New Roman ', ' bitstream Charter ', times,serif "><span style=" font-family:kaiti_gb2312 "><span style=" Color:rgb ( 51,51,51); font-family:georgia, ' Times New Roman ', ' bitstream Charter ', times,serif; line-height:21px "><span style=" font-size:14px "> <br> </span> </span> </span> </span> </span> </span> </span> </span> </span></span></span></span></span></span></span></strong></span></p><p><span style="font-family:KaiTi_GB2312"><strong><span style="color:rgb(51,51,51); font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif; line-height:21px"><span style="color:rgb(51,51,51); font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif; line-height:21px"><span style="font-size:14px"><span style="font-size:14px"><span style="font-family:kaiti_gb2312; font-size:18px"><span style="color:rgb ( 51,51,51); font-family:georgia, ' Times New Roman ', ' bitstream Charter ', times,serif; font-size:14px; line-height:21px "><span style=" font-family:kaiti_gb2312; font-size:18px "><span style=" font-family:Georgia, ' Times New Roman ', ' bitstream Charter ', times,serif; font-size:14px "><span style=" font-family:kaiti_gb2312 "><span style=" font-family:georgia, ' times New Roman ', ' Bitstream Charter ', times,serif "><span style=" font-family:kaiti_gb2312 "><span style=" font-family:georgia, ' Times New Roman ', ' bitstream Charter ', times,serif "><span style=" font-family:kaiti_gb2312 "><span style=" Color:rgb ( 51,51,51); font-family:georgia, ' Times New Roman ', ' bitstream Charter ', times,serif; line-height:21px "><span style=" font-size:14px "> <br> </span> </span> </span> </span> </span> </span> </span> </span> </span></span></span></span></span></span></span></strong></span></p><p><span style="font-family:KaiTi_GB2312"><strong><span style="color:rgb(51,51,51); font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif; line-height:21px"><span style="color:rgb(51,51,51); font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif; line-height:21px"><span style="font-size:14px"><span style="font-size:14px"><span style="font-family:kaiti_gb2312; font-size:18px"><span style="color:rgb ( 51,51,51); font-family:georgia, ' Times New Roman ', ' bitstream Charter ', times,serif; font-size:14px; line-height:21px "><span style=" font-family:kaiti_gb2312; font-size:18px "><span style=" font-family:Georgia, ' Times New Roman ', ' bitstream Charter ', times,serif; font-size:14px "><span style=" font-family:kaiti_gb2312 "><span style=" font-family:georgia, ' times New Roman ', ' Bitstream Charter ', times,serif "><span style=" font-family:kaiti_gb2312 "><span style=" font-family:georgia, ' Times New Roman ', ' bitstream Charter ', times,serif "><span style=" font-family:kaiti_gb2312 "><span style=" Color:rgb ( 51,51,51); font-family:georgia, ' Times New Roman ', ' bitstream Charter ', times,serif; line-height:21px "><span style=" font-size:14px "> well, The ListView performance Optimization said this, reprint please indicate the source--http://blog.csdn.net/u010687392 </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></strong></span></p><p><p><span style="font-family:KaiTi_GB2312"><strong><span style="color:rgb(51,51,51); font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif; line-height:21px"><span style="color:rgb(51,51,51); font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif; line-height:21px"><span style="font-size:14px"><br></span></span></span></strong></span></p></p><p><p><span style="font-family:KaiTi_GB2312"><strong><span style="color:rgb(51,51,51); font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif; line-height:21px"><span style="color:rgb(51,51,51); font-family:Georgia,‘Times New Roman‘,‘Bitstream Charter‘,Times,serif; line-height:21px"><span style="font-size:14px"><br></span></span></span></strong></span></p></p><p><p><span style="font-family:KaiTi_GB2312; font-size:14px"><br></span></p></p><p><p>Android performance Optimization ListView (viewholder Reuse Mechanism)</p></p></span>
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:
info-contact@alibabacloud.com
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