Java] package com. androidbook. controls;
Import android. app. Activity;
Import android. OS. Bundle;
Import android. view. ViewGroup. LayoutParams;
Import android. widget. LinearLayout;
Import android. widget. TextView;
Public class MainActivity extends Activity {
Private LinearLayout nameContainer;
Private LinearLayout addressContainer;
Private LinearLayout parentContainer;
/** Called when the activity is first created .*/
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
CreateNameContainer ();
CreateAddressContainer ();
CreateParentContainer ();
SetContentView (parentContainer );
}
Private void createNameContainer (){
NameContainer = new LinearLayout (this );
NameContainer. setLayoutParams (new LayoutParams (
LayoutParams. FILL_PARENT, LayoutParams. WRAP_CONTENT ));
NameContainer. setOrientation (LinearLayout. HORIZONTAL );
TextView nameLbl = new TextView (this );
NameLbl. setText ("Name :");
TextView nameValue = new TextView (this );
NameValue. setText ("Hohn Doe ");
NameContainer. addView (nameLbl );
NameContainer. addView (nameValue );
}
Private void createAddressContainer (){
AddressContainer = new LinearLayout (this );
AddressContainer. setLayoutParams (new LayoutParams (
LayoutParams. FILL_PARENT, LayoutParams. WRAP_CONTENT ));
AddressContainer. setOrientation (LinearLayout. VERTICAL );
TextView addrLbl = new TextView (this );
AddrLbl. setText ("Address :");
TextView addrValue = new TextView (this );
AddrValue. setText ("911 Hollywood Blvd ");
AddressContainer. addView (addrLbl );
AddressContainer. addView (addrValue );
}
Private void createParentContainer (){
ParentContainer = new LinearLayout (this );
ParentContainer. setLayoutParams (new LayoutParams (
LayoutParams. FILL_PARENT, LayoutParams. WRAP_CONTENT ));
ParentContainer. setOrientation (LinearLayout. HORIZONTAL );
ParentContainer. addView (nameContainer );
ParentContainer. addView (addressContainer );
}
}
From the column of horsttnann