Android ListView First Create GetView method to perform multiple issues

Source: Internet
Author: User

When writing the ListView optimization, it was found that the GetView method was executed multiple times when the ListView was first created.

<?XML version= "1.0" encoding= "Utf-8"?><Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:paddingbottom= "@dimen/activity_vertical_margin"Android:paddingleft= "@dimen/activity_horizontal_margin"Android:paddingright= "@dimen/activity_horizontal_margin"Android:paddingtop= "@dimen/activity_vertical_margin"Tools:context= "Com.example.hang.myapplication.MainActivity">        <ListViewAndroid:id= "@+id/list_item1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"            /></Relativelayout>


This is the layout of the ListView, after which the result is:

06-30 20:04:14.094 1166-1166/com.example.hang.myapplication d/hello:convertview is empty 006-30 20:04:14.104 1166-1166/ Com.example.hang.myapplication D/hello:convertview is empty 106-30 20:04:14.104 1166-1166/com.example.hang.myapplication D /hello:convertview is empty 206-30 20:04:14.114 1166-1166/com.example.hang.myapplication d/hello:convertview is empty 306-30 20:15:31.944 13339-13339/com.example.hang.myapplication D/hello:convertview is empty 006-30 20:15:31.944 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 106-30 20:15:31.954 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 206-30 20:15:31.954 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 306-30 20:15:31.954 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 006-30 20:15:31.954 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 106-30 20:15:31.954 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 206-30 20:15:31.954 13339-13339/ Com.example.hang.myapplication D/helLo:convertview not empty 306-30 20:15:31.984 13339-13339/com.example.hang.myapplication d/hello:convertview not empty 006-30 20:15:31.994 13339-13339/com.example.hang.myapplication D/hello:convertview is empty 106-30 20:15:31.994 13339-13339/ Com.example.hang.myapplication D/hello:convertview is empty 206-30 20:15:31.994 13339-13339/ Com.example.hang.myapplication D/hello:convertview is empty 306-30 20:15:32.054 13339-13339/ Com.example.hang.myapplication D/hello:convertview is empty 006-30 20:15:32.054 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 106-30 20:15:32.054 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 206-30 20:15:32.054 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 306-30 20:15:32.054 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 006-30 20:15:32.054 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 106-30 20:15:32.054 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 206-30 20:15:32.054 13339-13339/com.examPle.hang.myapplication D/hello:convertview not empty 306-30 20:15:32.124 13339-13339/com.example.hang.myapplication D/ Hello:convertview not empty 006-30 20:15:32.134 13339-13339/com.example.hang.myapplication d/hello:convertview not empty 106-30 20:15:32.134 13339-13339/com.example.hang.myapplication d/hello:convertview not empty 206-30 20:15:32.134 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 306-30 20:15:32.134 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 006-30 20:15:32.134 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 106-30 20:15:32.134 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 206-30 20:15:32.134 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 3

This is obviously not normal, and several getview methods have been executed. After the group friend's prompt modified to fill_partent, the result shows normal.

06-30 20:04:14.094 1166-1166/com.example.hang.myapplication d/hello:convertview is empty 006-30 20:04:14.104 1166-1166/ Com.example.hang.myapplication D/hello:convertview is empty 106-30 20:04:14.104 1166-1166/com.example.hang.myapplication D /hello:convertview is empty 206-30 20:04:14.114 1166-1166/com.example.hang.myapplication D/hello:convertview is empty 3

Later Lenovo to the UI optimization, suddenly dawned ~

relativelayouts often needs to measure all child nodes two times to get the proper layout of the nodes. If the child node has the weights attribute set, linearlayouts also needs to measure these nodes two times to get an accurate display size.  

view starts being measure, all of the view's sub-view is re-layout, and the view is passed to its parent view, so that it repeats to the top of the root view. When layout is complete, all views are rendered to the screen and not only the view that the user sees is rendered, but all the view will. Such a view will be measure multiple times. Getiew also executed several times.

06-30 20:25:18.314 13339-13339/com.example.hang.myapplication d/hello:convertview is empty 006-30 20:25:18.324 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 106-30 20:25:18.324 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 206-30 20:25:18.324 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 306-30 20:25:18.324 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 006-30 20:25:18.324 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 106-30 20:25:18.324 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 206-30 20:25:18.324 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 306-30 20:25:18.324 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 006-30 20:25:18.324 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 106-30 20:25:18.324 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 206-30 20:25:18.334 13339-13339/com.example.hang.myapplication D/hello:convertview not empty 306-30 20:25:18.334 13339-13339/com.example.hang.myapplication D/hello: Convertview not empty 006-30 20:25:18.334 13339-13339/com.example.hang.myapplication d/hello:convertview not empty 106-30 20:25:18.334 13339-13339/com.example.hang.myapplication d/hello:convertview not empty 206-30 20:25:18.334 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 306-30 20:25:18.344 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 006-30 20:25:18.344 13339-13339/ Com.example.hang.myapplication D/hello:convertview is empty 106-30 20:25:18.354 13339-13339/ Com.example.hang.myapplication D/hello:convertview is empty 206-30 20:25:18.354 13339-13339/ Com.example.hang.myapplication D/hello:convertview is empty 306-30 20:25:18.404 13339-13339/ Com.example.hang.myapplication D/hello:convertview is empty 006-30 20:25:18.404 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 106-30 20:25:18.404 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 206-30 20:25:18.414 13339-13339/com.example.hang.myapplication D/hello:convertview not empty 306-30 20:25:18.414 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 006-30 20:25:18.414 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 106-30 20:25:18.414 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 206-30 20:25:18.414 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 306-30 20:25:18.414 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 006-30 20:25:18.414 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 106-30 20:25:18.414 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 206-30 20:25:18.414 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 306-30 20:25:18.414 13339-13339/com.example.hang.myapplication d/hello:convertview not empty 006-30 20:25:18.414 13339-13339/com.example.hang.myapplication D/hello:convertview not empty 106-30 20:25:18.414 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 206-30 20:25:18.414 13339-13339/ Com.example.hang.myapplication D/hello:convertview not empty 3

Solution, set to Fill_partent or set to a fixed value to optimize the UI layout.

Android ListView First Create GetView method to perform multiple issues

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