Three ways to populate the interface layout in Android

Source: Internet
Author: User


Three ways to change the layout of the original interface:


1, the first way:

Layoutinflater li = Layoutinflater.from (this);


Specific code:

public class Mainactivity extends Activity {

@Override

protected void onCreate (Bundle savedinstancestate) {

super.oncreate (savedinstancestate);

Setcontentview (r.layout.activity_main); The original layout

}

public void Click (View view) {

//Change the layout of this interface

//Layout filler

There are three ways to get this object:

Layoutinflater ll = Layoutinflater.from (this); Get a Fill object


View v = ll.inflate (r.layout.login, NULL); //Reload layout

Setcontentview (v); //Fill layout

}

}



2, the second way:

Layoutinflater li = Getlayoutinflater ();


Specific code:

public class Mainactivity extends Activity {

@Override

protected void onCreate (Bundle savedinstancestate) {

super.oncreate (savedinstancestate);

Setcontentview (r.layout.activity_main); The original layout

}

public void Click (View view) {

//Change the layout of this interface

//Layout filler

There are three ways to get this object:

Layoutinflater out = Getlayoutinflater (); Get a Fill object

View v = out.inflate (r.layout.login, NULL); //Load Layout file

Setcontentview (v); //Fill layout

}

}


3, the Third Way:

Layoutinflater ll= (Layoutinflater) Getsystemservice (Co ntext. Layout_inflater_service);


Specific code:

public class Mainactivity extends Activity {

@Override

protected void onCreate (Bundle savedinstancestate) {

super.oncreate (savedinstancestate);

Setcontentview (r.layout.activity_main);//The original layout

}

public void Click (View view) {

//Change the layout of this interface

//Layout filler

There are three ways to get this object:

layoutinflater ll= (layoutinflater) Getsystemservice (Context.layout_inflater_service); //Get Fill object

View v = ll.inflate (r.layout.login, NULL); //Load Layout file

Setcontentview (v); //Fill layout

}

}

In the example there are two layout files activity_main.xml and login.xml which can be arbitrarily defined.


This article is from the "Beginner" blog, so be sure to keep this source http://10154241.blog.51cto.com/10144241/1663955

Three ways to populate the interface layout in Android

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.