Code example for TableLayout

Methods: setGravitysetOrientationaddView, setLayoutParams

0
		super.onCreate(savedInstanceState);
		loadViews(); 
	} 
 
	private void loadViews() { 
		Container = new TableLayout(this.getBaseContext());
		Container.setOrientation(TableLayout.VERTICAL);
		TableLayout.LayoutParams tl =
				new TableLayout.LayoutParams(LayoutParams.FILL_PARENT,
						LayoutParams.FILL_PARENT);
		Container.setLayoutParams(tl);
		Container.setGravity(Gravity.CENTER_HORIZONTAL);
 
		TipsContainer = new LinearLayout(this.getBaseContext());
		TipsContainer.setOrientation(LinearLayout.VERTICAL);
		LinearLayout.LayoutParams lp = 
				new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
						LayoutParams.WRAP_CONTENT);
		lp.gravity = Gravity.CENTER_HORIZONTAL;
		TipsContainer.setGravity(Gravity.CENTER_HORIZONTAL);
		Container.addView(TipsContainer, lp);
 
		StageGellery = 
				new SlidingLayoutWithAnim( 
						this.getBaseContext());
		tl = new TableLayout.LayoutParams(LayoutParams.FILL_PARENT,
				StageGalleryHeight);
		Container.addView(StageGellery, tl);
		StageGellery.setListener(this);
		 
		StageText = new TextView(this.getBaseContext());
		tl = new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
				StageTextHeight);
		tl.gravity = Gravity.CENTER;
		StageText.setGravity(Gravity.CENTER);
		Container.addView(StageText, tl);
		 
		RelativeLayout.LayoutParams rl = new RelativeLayout.LayoutParams(  
				RelativeLayout.LayoutParams.FILL_PARENT,  
				RelativeLayout.LayoutParams.FILL_PARENT);
		Root.addView(Container, rl);
	} 
	 
	public class StageInfo { 
		public ImageView iv = null;
		public String name = null;