Android Setcontentview and Layoutinflater

Source: Internet
Author: User

Setcontentview:

1. Commonly used constructors:

  1) setcontentview (int layoutresid)  2) Setcontentview (view view)  3) Setcontentview (view view, Viewgroup.layoutparams params)

2. Usage

1) Setcontentview (R.layout.main);
2) Layoutinflater Inflater = (layoutinflater) getsystemservice (Context.layout_inflater_service);
true);
Setcontentview (view);

3. Application scenarios for two uses:

Setcontentview () Once called, Layout will display the UI immediately, and inflate will only form an object that is implemented in the view class, and then displayed with the Setcontentview (view) when necessary.

The interface is typically displayed in activity through Setcontentview (), but dynamic loading is required if you want to set up the control layout in a non-activity way.

Layoutinflater:

Three ways to get Layoutinflater instances

1. Layoutinflater inflater = Getlayoutinflater ();  // call Activity Getlayoutinflater ()2. Layoutinflater Localinflater = (layoutinflater) context.getsystemservice (Context.layout_inflater_service); 3. Layoutinflater Inflater = layoutinflater.from (context);     

In fact, these three ways are essentially the same, from the source can draw the conclusion : The final essence of these three ways is called context.getsystemservice ().

Android Setcontentview and Layoutinflater

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.