How can I add borders to a TableLayout
through code ?
TableLayout in xml
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</TableLayout>
My code
TableLayout prices = (TableLayout)findViewById(R.id.tableLayout1);
prices.setStretchAllColumns(true);
prices.bringToFront();
for(int i = 0; i < 1; i++){
TableRow tr = new TableRow(this);
TextView c1 = new TextView(this);
c1.setText(equipHere);
c1.setTextColor(Color.BLACK);
c1.setTextSize(15);
TextView c2 = new TextView(this);
c2.setText("No of Days("+daysHere+")");
c2.setTextColor(Color.BLACK);
c2.setTextSize(15);
tr.addView(c1);
tr.addView(c2);
prices.addView(tr);
}
create a xml file with the following code and place in the drawable folder
and set the xml as a background resource drawable for the table layout.
Do following:
Create
Gradient
intores\xml\table.xml
like:And set to your
TableLayout
backgroundAnd Programmatically you can achieve like: