I have tried everything to divide a tablelayout into 2 columns or more, but I dont know how, any help?
<TableLayout
android:id="@+id/exercisetableviewing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_x="5dp"
android:background="@layout/border"
android:layout_y="289dp" >
</TableLayout>
I add a row in the table using :
private void fillTable(TableLayout tableLayout, String[] items) {
for (int i = 0; i < items.length; i++) {
TextView itemText = new TextView(FillingActivity.this);
itemText.setText(items[i]);
TableRow row = new TableRow(FillingActivity.this);
row.addView(itemText);
if(i % 2 == 1)
row.setBackgroundColor(color.LightGreen);
tableLayout.addView(row);
}
}
You should define an xml for your text view, with:
The “weight” attribute is used to say All the text views will use the same width in the row.
TableRow extends LinearLayout so you can use LinearLayout’s attributes.
Then inflate your view in your code like this:
Now, in your code, you only add one TextView to your TableRow. Is it the normal behavior? You talk about two columns but you only ad one in your row…