I am developing an application in which i am generating rows programmatically as :

TableLayout tableLayout = (TableLayout) findViewById(R.id.tablelayout);
for(int j=0; j<50; j++){
    TableRow tableRow = new TableRow(this);
    tableRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
    for(int i = 0; i<10; i++){
        TextView t = new TextView(this);
        t.setText("Dynamic TV");
        t.setPadding(10, 10, 10, 10);
        t.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
        tableRow.addView(t);

        // Added Horizontal line as
        View view=new View(this);
        view.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, 1));
        view.setBackgroundColor(Color.rgb(50, 50, 50));
        tableLayout.addView(view);
    }
    tableLayout.addView(tableRow, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT,0.1f));
}

In this i inserted horizontal line but my need is:

1. I want vertical line as a column seperater, and

2. Want to reduce height of horizontal line.

I tried various ways but not able to achive the task. Please guide me how to do this.

有帮助吗?

解决方案

To add vertical separator and set the height 1px you can try this

TableLayout tableLayout = (TableLayout) findViewById(R.id.tablelayout);
for (int j = 0; j < 50; j++) {
TableRow tableRow = new TableRow(this);
tableRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
for (int i = 0; i < 10; i++) {
TextView t = new TextView(this);
t.setText("Dynamic TV");
t.setPadding(10, 10, 10, 10);
t.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
tableRow.addView(t);

// Add vertical separator
                View v = new View(this);
                v.setLayoutParams(new TableRow.LayoutParams(1, TableRow.LayoutParams.MATCH_PARENT));
                v.setBackgroundColor(Color.rgb(50, 50, 50));
                tableRow.addView(v);
            }
            // Added Horizontal line as
            View view = new View(this);
            view.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, 1));
            view.setBackgroundColor(Color.rgb(50, 50, 50));
            tableLayout.addView(view);

tableLayout.addView(tableRow, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT, 0.1f));

其他提示

Try the following code :

// Added Horizontal line as
    View view1=new View(this);
    view1.setLayoutParams(new TableRow.LayoutParams(1, TableRow.LayoutParams.MATCH_PARENT));
    view1.setBackgroundColor(Color.rgb(50, 50, 50));
    tableLayout.addView(view1);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top