In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to use Android ViewStub". In daily operation, I believe many people have doubts about how to use Android ViewStub. Xiaobian consulted all kinds of materials and sorted out simple and easy operation methods. I hope to help you answer the doubts about "how to use Android ViewStub"! Next, please follow the small series to learn together!
Sometimes, our page may contain some layouts that are hidden by default, and hidden layouts will only be displayed after the user triggers certain actions. For example, we have an Activity that displays a list of friends. When the user clicks "Import" in the Menu, a layout interface for importing friends will be displayed in the current Activity. From the perspective of requirements, this import function is generally not used by users. That is, most of the time, the layout of imported friends will not be displayed. At this point, you can use the delayed loading function.
ViewStub is a hidden, memory-free view object that can load layout resource files late at runtime. The layout resource file is actually loaded when ViewStub is set to visible, or when the inflate() function is called. The ViewStub replaces itself in the parent container when the view is loaded. Therefore, ViewStub remains in the view until setVisibility(int) or inflate() is called. The ViewStub layout parameters are added to the ViewStub parent container along with the number of views loaded. Similarly, you can define or rename the Id value of the View object to be loaded by using the inflated Id attribute.
Please refer to the code snippet below.
The defined ViewStub object can be found by the id "stub_import". After loading the layout asset file "progress_overlay," the ViewStub object is removed from its parent container. Views created by the layout asset "progress_overlay" can be found by the id "panel_import."
The recommended way to load 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, the ViewStub is replaced by the loaded view and returns the view object. This eliminates the need for the application to execute additional findViewById() to get a reference to the loaded view.
Experience sharing:
ViewStub can be associated with the specified layout resource file in the xml file, so that the layout resource file can be loaded when needed. When to load, not at the beginning of the boot. Doing so will speed up your app startup and save memory resources.
At this point, the study of "how to use Android ViewStub" is over, hoping to solve everyone's doubts. Theory and practice can better match to help you learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.