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