For those not happy with having to pre-define your sizes, I found a bit of a hack that's working for me.
Basically, make a separate table for the title and put it over your main table, but with the same Top alignment, then create two copies of the title row and after adding one to the main table, add the other to the title table and set the child view's layoutParams to the row form the main table.
Here's my basic example.
in your layout:
<HorizontalScrollView
android:id="@+id/table_horizontal_scroll_view"
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:clickable="false">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ScrollView
android:layout_alignParentTop="true"
android:layout_marginTop="0dp"
android:id="@+id/table_vertical_scroll_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/grid_table_layout"
/>
</ScrollView>
<TableLayout
android:layout_alignLeft="@+id/table_vertical_scroll_view"
android:layout_alignRight="@+id/table_vertical_scroll_view"
android:layout_alignStart="@+id/table_vertical_scroll_view"
android:layout_alignEnd="@+id/table_vertical_scroll_view"
android:layout_alignParentTop="true"
android:background="@color/grid_view_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/grid_floating_row_layout"
/>
</RelativeLayout>
</HorizontalScrollView>
Then when you add your rows:
//clear out any views
tableLayout.removeAllViews();
floatingRowLayout.removeAllViews();
TableRow[] rows = getTableContentRows() // content of your table
TableRow[] titleRows = {getTitleRow(), getTitleRow()}; //two copies of your title row
tableLayout.addView(titleRows[0]); // first add the first title to the main table
addRows(rows) // add any other rows
floatingRowLayout.addView(titleRows[1]); // floatingRowLayout is connected to id/grid_floating_row_layout
titleRows[0].setVisibility(View.INVISIBLE); // make the title row added to the main table invisible
// Set the layoutParams of the two title rows equal to each other.
// Since this is done after the first is added to the main table, they should be the correct sizes.
for(int i = 0; i < titleRows[0].getChildCount(); i++) {
titleRows[1].getChildAt(i).setLayoutParams(titleRows[0].getChildAt(i).getLayoutParams());
}