Android ListView GetView () method repeated calls cause position dislocation

Source: Internet
Author: User

Problem Status: Android ListView GetView () method repeated calls cause position dislocation

Workaround: Change the Layout_height property of the ListView layout file to Fill_parent or match_parent.

<listview
Android:id= "@+id/myphoto_listview"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
Android:layout_margin= "10DP"
android:dividerheight= "5px"
Android:listselector= "@android: Color/transparent" >
</ListView>

An explanation of the original author: (From: http://blog.csdn.net/f8376904110/article/details/6460934)

When we are using the ListView. Sometimes when customizing the adapter, will it be found in the GetView to print the log, repeated calls many times? Sometimes 4 times. Some are serious even to 10 times when we move in the ListView. Each column will be called many times, which greatly affects the efficiency! This is in fact related to the mechanism of the ListView itself on Android. Let me start by introducing you:

In the layout, we only have one ListView at a time. All right. When we set the height to wrap_content. In the ListView add a few lines to see. The logs are printed in the GetView. Did you call it repeatedly? That's a good way to get it. Set the height into fill_parent. Does this time find the log or repeat call? It is necessary to look at the upper level of the ListView is also the setting is also fill_parent, if not. Please change it. If it is ... Then I really did not touch the repeated call! Because of the test several times!

If we're in there, there's more than one listview. A complex good-looking layout may be a lot. The ListView is somewhere in the layout. Sometimes it's bad luck at this time. You will find that you have called many times getview. When I was testing. Up to 230 times ... Imagined. This speed is quite slow. And every move is called so many times! In this case, when modifying the layout, consider the following two points: 1. First consider the layout and performance of the requirements which is more important. 2. Consider which layout control around the ListView affects it!

If there is not much impact on performance, the requirements must be the same layout. That is the layout of the main. See if there is any other way to optimize the ListView, but the premise is that the layout cannot be adjusted at all. If you can adjust, the layout doesn't change much. And the ListView can be well optimized. That's certainly optimized! When we are optimizing. The first step is to see if there are controls that affect the ListView redraw, such as. If it has controls above and below it. And high are wrap_content, then you will be set to fill_parent or fixed high. This is the main point when the ListView is not redrawn on the high. Is there a control around there (there is no such a lot of controls when a mobile page is used in a list)? Well, then we'll have to adjust, that's the same setting as high. Make sure the ListView is fixed in that place. Otherwise, you just wait for him to repeat the call!

Actually said so much. The main thing is when we're laying out. To skillfully apply the properties of each control, and to understand the principle of each control. So when we do UI design, can be very good to combine!

Android ListView GetView () method repeated calls cause position dislocation

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: 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

  • 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.