I follow this How can I create a table with borders in Android? Which is very helpful, but unable to create column border only row border displaying in my case.
My code:
TableLayout.LayoutParams tableLayoutParams = new
TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT);
TableLayout tableLayout = new TableLayout(getContext());
tableLayout.setBackgroundColor(Color.WHITE);
tableRowParams = new TableRow.LayoutParams(
android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
tableRowParams.setMargins(1, 1, 1, 1);
//tableRowParams.weight = 1;
for (i = 0; i < row + 1; i++) {
tableRow = new TableRow(getContext());
tableRow.setGravity(Gravity.CENTER_VERTICAL);
//tableRow.setBackgroundColor(Color.BLACK);
tableRow.setPadding(2, 2, 2, 2);
tableRow.setBackgroundResource(R.drawable.cell_shape_new);
for (j = 0; j < col + 1; j++) {
LinearLayout ll = new LinearLayout(getContext());
ll.setLayoutParams(new LayoutParams(
android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
ll.setOrientation(1);
TextView textView = new TextView(getContext());
textView.setTextSize(25);
textView.setTextColor(Color.BLACK);
textView.setGravity(Gravity.CENTER);
//Display required field
}
}
}
R.drawable.cell_shape_new
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape= "rectangle" >
<solid android:color="#FFFFFF"/>
<stroke android:width="2dp" android:color="#000000"/>
</shape>
My output :
How to put column border here.