Scroll bar for TableLayout
<p>I trying to place the scroll bar (both Vertical and Horizontal) for the table layout.</p>

<p>Here is my xml:</p>

<pre><code>&lt;ScrollView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="40"
    android:fillViewport="true"&gt;

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

        &lt;TableLayout
            android:id="@+id/prize_table"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:padding="10dp"
            android:shrinkColumns="*"
            android:stretchColumns="*" /&gt;
    &lt;/HorizontalScrollView&gt;
&lt;/ScrollView&gt;
</code></pre>

<p>This is how I add the table row:</p>

<pre><code>// header
row = new TableRow(MainActivity.this);
row.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

tv = new TextView(MainActivity.this);
tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
tv.setTextSize(18);
tv.setPadding(0, 5, 0, 5);
tv.setText(R.string.prize_no);
row.addView(tv);

tv = new TextView(MainActivity.this);
tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
tv.setTextSize(18);
tv.setPadding(0, 5, 0, 5);
tv.setText(R.string.prize_name);
row.addView(tv);

layout.addView(row);

for (Prize prize : prizes) {
    row = new TableRow(MainActivity.this);
    row.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    tv = new TextView(MainActivity.this);
    tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    tv.setTextSize(18);
    tv.setPadding(0, 5, 0, 5);
    tv.setText(prize.getPrizeID());
    row.addView(tv);

    tv = new TextView(MainActivity.this);
    tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    tv.setTextSize(18);
    tv.setPadding(0, 5, 0, 5);
    tv.setText(prize.getPrizeName());
    row.addView(tv);

    layout.addView(row);
}
</code></pre>

<p>But I have some problem with these code</p>

<ol>
<li>The vertical scroll bar cannot match with my content, let say I have 10 rows, but the scroll bar will be 10 times longer</li>
<li>The horizontal scroll bar is missing</li>
</ol>

<p>Could anyone point out what problem in my code? Thanks in advance</p>