Code example for TableLayout

Methods: addViewsetColumnStretchable, setLayoutParams

0
 
	createTableLayout(); 
    } 
 
    private void createTableLayout() { 
	TableLayout tableLayout = new TableLayout(this);
	tableLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
		LayoutParams.FILL_PARENT));
	tableLayout.setColumnStretchable(1, true);
 
	// Linha 1 
	TableRow row1 = new TableRow(this);
 
	TextView nomeTextView = new TextView(this);
	nomeTextView.setText("Nome:");
	row1.addView(nomeTextView);
 
	EditText nomeEditText = new EditText(this);
	nomeEditText.requestFocus();
	row1.addView(nomeEditText);
 
	// Linha 2 
	 
	TableRow row2 = new TableRow(this);
	 
	TextView senhaTextView = new TextView(this);
	senhaTextView.setText("Senha:");
	row2.addView(senhaTextView);
	 
	EditText senhaEditText = new EditText(this);
	senhaEditText.setTransformationMethod(new PasswordTransformationMethod());
	row2.addView(senhaEditText);
	 
	// Linha 3 
	 
	TableRow row3 = new TableRow(this);
	row3.setGravity(Gravity.RIGHT);
	 
	Button okButton = new Button(this);
	okButton.setText(" LOGIN ");
	row3.addView(okButton);
		 
	 
	// Fim 
	 
	tableLayout.addView(row1);
	tableLayout.addView(row2);
	tableLayout.addView(row3);
 
	setContentView(tableLayout);
    } 
 
}