How to set TableRow width to max in Android?
<p>I have a table defined in .xml file but rows and headers have to be added dynamically. I have a problem with fill width with table row on horizontal and vertical orientation. I have tried stretchColumns parameter but it did not help. What is the best way to do it?</p>

<pre><code>            table = (TableLayout) findViewById(R.id.testList);

        TableRow headerRow  = new TableRow(this);

        JSONObject obj;

        obj = new JSONObject(loadJSONFromAsset());

        JSONArray records = obj.getJSONArray("tests");

        ArrayList&lt;String&gt; headers = new ArrayList&lt;&gt;();
        headers.add("Header 1");
        headers.add("Header 2");
        headers.add("Header 3");
        headers.add("Header 4");
        headers.add("Header 5");

        for(int i = 0; i &lt; headers.size(); i++) {
            TextView header = new TextView(this);
            header.setText(headers.get(i));
            header.setTextColor(Color.WHITE);
            header.setBackgroundColor(Color.rgb(24, 116, 205));
            header.setPadding(15, 15, 15, 15);
            header.setTextSize(20);
            header.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);

            header.setMaxLines(1);
            headerRow.addView(header);

        }

        table.addView(headerRow);
</code></pre>

<p>and xml</p>

<pre><code>&lt;GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="wrap_content"&gt;


&lt;LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"&gt;

    &lt;ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"&gt;

        &lt;HorizontalScrollView
            android:layout_height="wrap_content"
            android:layout_width="match_parent"&gt;

            &lt;TableLayout
                android:id="@+id/testList"
                android:layout_height="match_parent"
                android:layout_width="wrap_content"&gt;

            &lt;/TableLayout&gt;
        &lt;/HorizontalScrollView&gt;
    &lt;/ScrollView&gt;

&lt;/LinearLayout&gt;

&lt;/GridLayout&gt;
</code></pre>