Android's Viewstub

Source: Internet
Author: User

In everyday XML layouts we often use the <include/> tags to reuse some layout layouts, but in some cases some reuse layout is rarely used (or, in other words, rarely shown). Use <viewstub in this case /> Label overrides <include/> tags so that the seldom-used layout is not loaded into the main layout file, saving load time and overhead, When we need to use this layout, we can directly call the inflate () method in viewstub to display the layout file of the reuse.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/58/06/wKiom1Sn9vbwe5cyAADCcdzGUCE480.jpg "title=" 1.png " alt= "Wkiom1sn9vbwe5cyaadccdzguce480.jpg"/>

Using the Viewstub property is actually very simple, and the code snippet in the XML layout is as follows.

<viewstub android:id= "@+id/stub" android:inflatedid= "@+id/subtree" android:layout= "@layout/view_stu B_test "android:layout_width=" wrap_content "android:layout_height=" Wrap_content "/>

Explain a few 2 properties:

android:layout= "@layout/view_stub_test"

This property, like the Layout property in the <include/> tag, indicates the layout of the fill.

Android:inflatedid= "@+id/subtree"

This property is actually a renaming of the filled layout layouts.

If you need to use the filled layout layouts (that is, view_stub_test) in your code, simply call the following

Viewstub = (viewstub) Findviewbyid (r.id.stub); Viewstub.inflate ();


Android's Viewstub

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.