Pre-loading mechanism for integrated use of Viewpager and fragment

Source: Internet
Author: User

Mixed adapter: Fragmentpageradapter Fragmentstatepageradapter (fragment data is more dynamic and memory intensive)

Viewpager Pre-load: Viewpager will default to pre-initialize the current page of the left and right adjacent pages, its pre-loaded page number default is 1,

And it is private can not be modified, the advantage is that the left and right sliding will be more fluent.

Lazy loading: That is, let the Viewpager preload the UI, while the specific data, network access requests, and other deferred loading. It's a fragment.

Setuservisiblehint (Boolean Isvisibletouser) method, which we can judge in this method, when its true is visible

(that is, switch to a specific fragment) to load the data, which saves traffic.

Issues that can be resolved:

5 Fragment There is a fragment is surfaceview, so the problem is, I viewpager sliding to its adjacent page, the page containing Surfaceview will be pre-initialized, Then the Surfaceview began to preview, but we could not see it. Similarly, Surfaceview does not call back its Surfacedestory method when we slide down its adjacent page from a page that contains Surfaceview. So it caused me a great deal of trouble.

setoffscreenpagelimit (int limit) to set the number of Viewpager preload

The Viewpager member variable default_offscreen_pages here defines the default value is 1, so there is a solution on the web that calls Viewpager's setoffscreenpagelimit (int limit),

Pre-loading mechanism for integrated use of Viewpager and fragment

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.