This blog article mainly discusses a common technology in complex interfaces-interface delay loading technology.
Sometimes, our pages may contain some la S. These la s are hidden by default. After a user triggers some operations, the hidden la s are displayed. For example, an activity is used to display the list of friends. After you click "import" in the menu, a layout interface for importing friends is displayed in the current activity. From the perspective of requirements, this import function is generally not used by users. In most cases, the layout of imported friends is not displayed. In this case, you can use the delayed loading function.
Viewstub is a hidden view object that does not occupy memory space. It can load layout resource files at runtime delay. When viewstub is set to visible or the inflate () function is called, the layout resource file is loaded. This viewstub replaces itself in the parent container when loading the view. Therefore, viewstub will remain in the view until setvisibility (INT) or inflate () is called. The layout parameters of viewstub are added to the parent container of viewstub along with the number of loaded views. Similarly, you can use the inflated ID attribute to define or rename the id value of the view object to be loaded.
See the following code snippet.
<Viewstub Android: Id = "@ + ID/stub_import" Android: inflatedid = "@ + ID/panel_import" Android: Layout = "@ layout/progress_overlay" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: layout_gravity = "bottom"/> |
The ID "stub_import" can be used to find the defined viewstub object. After the layout resource file "progress_overlay" is loaded, the viewstub object is removed from its parent container. You can use the "panel_import" ID to find the view created by the layout resource "progress_overlay.
The recommended method for loading layout resource files is as follows:
(Viewstub) findviewbyid (R. Id. stub_import). setvisibility (view. Visible ); // Or View importpanel = (viewstub) findviewbyid (R. Id. stub_import). Inflate (); |
When inflate () is called, this viewstub is replaced by the loaded view, and this view object is returned. In this way, the application does not need to execute findviewbyid () to obtain reference for loading views.
Experience Sharing: Viewstub can be used to associate with the specified layout resource file in the XML file, so that the layout resource file can be loaded as needed. When to load data, instead of loading data at startup. This can speed up application startup and save memory resources. |
Blog related to optimization series:
Android development optimization-memory optimization for bitmap
Android development optimization-using soft references and weak references
Android development optimization-code optimization
Android development optimization-UI optimization (1)
Android development optimization-UI optimization (2)
---------------------------------------------------------------------------
Http://blog.csdn.net/arui319
An excellent solution for Android Application Development has been published. This article is part of the first draft. Welcome to purchase and read.
This article can be reproduced, but please keep the above author information.
Thank you.
---------------------------------------------------------------------------