Setcontentview and layoutinflater for Android

Source: Internet
Author: User

Setcontentview:

1. Common constructor:

 
1) setcontentview (IntLayoutresid)

2) setcontentview (view)

3) setcontentview (view, viewgroup. layoutparams Params)

2. Usage

 
1) setcontentview (R. layout. Main );

2) layoutinflater Inflater = (layoutinflater) getsystemservice (context. layout_inflater_service );

View view = (View) Inflater. Inflate (R. layout. apploader,Null,True);

Setcontentview (View );

3. Use Cases:

Once setcontentview () is called, layout will immediately display the UI. Inflate will only form a ready-made object in the View class and display it with setcontentview (View) when necessary.

Generally, the interface is displayed through setcontentview () in the activity. However, if you want to set the layout of the control in a non-activity, you need layoutinflater to dynamically load it.

 

Layoutinflater:

Three methods for obtaining a layoutinflater instance

 
1. layoutinflater Inflater = getlayoutinflater ();//Call getlayoutinflater () of the activity ()

2. layoutinflater localinflater = (layoutinflater) Context. getsystemservice (context. layout_inflater_service );

3. layoutinflater Inflater = layoutinflater. From (context );

In fact, these three methods are essentially the same. We can draw a conclusion from the source code.: The three methods are called in essence.Context. getsystemservice ().


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.