How can I set tablerow of differnt width in Tablelayout?

Issue

This Content is from Stack Overflow. Question asked by Saurabh Jadhav

My expected Output

This is referenced Image of what I want,
But im unable to do it, currently im using tablelayout, what i should do?
Ofcourse my total requirement are vertical and horizontal scrolling.

My current code is below with this I cant even have row of diff width, same width get applied to all below rows of column

/* create cell element - button */
        for (int i = 0; i < 14; i++) {

            if (i == 0) {
                TableRow.LayoutParams tableRowParams = new TableRow.LayoutParams(
                            100,
                        100);
//                tableRowParams.column=1;
//                tableRowParams.span=2;
                TableRow tableRow = new TableRow(this);
                View v = LayoutInflater.from(this).inflate(R.layout.item_header, tableRow, false);
                tableRow.setLayoutParams(tableRowParams);
                TextView tv_label = (TextView)v.findViewById(R.id.tv_label);
                LinearLayout ll_row = (LinearLayout)v.findViewById(R.id.ll_row);
                tv_label.setText("dynamic " + i);
                ll_row.setBackgroundColor(Color.parseColor("#6ab04c"));
//                ll_row.getLayoutParams().height = 100;
//                ll_row.getLayoutParams().width = 400;
//                ll_row.requestLayout();
                tableRow.addView(v);
                tableLayout.addView(tableRow);
            } else {
                TableRow.LayoutParams tableRowParams = new TableRow.LayoutParams(
                        LinearLayout.LayoutParams.WRAP_CONTENT,
                        LinearLayout.LayoutParams.WRAP_CONTENT);
//                tableRowParams.column=1;
//                tableRowParams.span=1;

                TableRow tableRow = new TableRow(this);
                View v = LayoutInflater.from(this).inflate(R.layout.item_header, tableRow, false);
                tableRow.setLayoutParams(tableRowParams);
                TextView tv_label = (TextView)v.findViewById(R.id.tv_label);
                LinearLayout ll_row = (LinearLayout)v.findViewById(R.id.ll_row);
                tv_label.setText("dynamic " + i);
                ll_row.setBackgroundColor(Color.parseColor("#6ab04c"));
//                ll_row.getLayoutParams().height = 300;
//                ll_row.getLayoutParams().width = 200;
//                ll_row.requestLayout();
                tableRow.addView(v);
                tableLayout.addView(tableRow);
            }


        }

My current Output is this:
My Current Output



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?