I've got a ScrollView that holds a TableLayout. The tablelayout is activated programmatically when an AsyncTask finishes fetching data for me. A method then builds TableRows based on the amount of data returned and attaches them to the TableLayout.
In XML, the only item within the TableLayout is a ProgressBar. Here's the XML:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/electionsScrollView" android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableLayout android:id="@+id/electionsQuestionContainer"
android:layout_width="match_parent" android:layout_height="wrap_content">
<ProgressBar android:id="@+id/electionsProgressBar"
style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_gravity="center_vertical|center_horizontal" />
</TableLayout>
</ScrollView>
I obviously can't put the ProgressBar right inside the scrollview, as the scrollview can only host one item (the tablelayout). I imagine that I don't want to place the ProgressBar in a table row, as I imagine that would be more troublesome to remove than the AsyncTask just running progressBar.setVisibility(View.GONE);. So is a tableRow my only option, or is there a reason why my ProgressBar is not centering in the middle of the screen, both vertically and horizontally?
I am about half way there. By changing the TableLayout's layout_gravity:
<TableLayout android:id="@+id/electionsQuestionContainer"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal">
But, that ruins the appearance when I programmatically add in rows. Does anyone know which Gravity.CONSTANT will make the tableLayout return to default? When I hadn't set anything for the TableLayout's layout_gravity it looked perfect. So now, I have the ProgressDialog looking exactly as I like, but the populated in rows don't look right. What's wrong? The top tablerow is about half way off the top portion of the screen (in other words, I can only see half of the first table row, the rest is off of the top of the screen and cant be scrolled to reach).
I ended up using two separate layouts, and removing the old.