Android Optimization-UI optimization (3)

Source: Internet
Author: User

Android Optimization-UI optimization (3)
UseViewStubDelayed Loading

1. ViewStubDelayed Loading

ViewStub is an invisible View with a size of 0. The best use is to implement delayed loading of the View and load the View as needed, the common performance optimization methods in Java are the same for delayed loading.
When the setVisibility function of ViewStub is called to be visible or inflate is called to initialize the View, the resources referenced by ViewStub start initialization, and then the referenced resources replace ViewStub's position and fill in the ViewStub position. Therefore, ViewStub exists in the component tree hierarchy before the setVisibility (int) or the inflate () function is called. However, ViewStub is lightweight and has little impact on performance. You can use the inflatedId attribute of ViewStub to redefine the referenced layout id. For example:

Xml

  
Java
// Obtain viewstubfinal ViewStub stub = (ViewStub) findViewById (R. id. stub); // use inflate () to fill the layout with Handler handler = new Handler () {@ Override public void handleMessage (Message msg) {View view = stub. inflate () ;}}; handler. sendEmptyMessageDelayed (1, 7000 );

I have called it for a while.stub.inflate();Method to load the layout. Here we do not need to load the view with findViewById.

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.