I had a TableLayout and wanted to centralise it in a ScrollView. With the following code, the table was centralised as seen in the design view, but did not work on the Emulator or on the phone.
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<TableLayout
android:gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="*">
....
</TableLayout>
</ScrollView>
On preview mode, it looks like this:
But on the emulator, the text is not centralized:
I have tried 2 things:
- wrap TableLayout with a LinearLayout
- replace ScrollView with RelativeLayout and set
android:layout_centerVertical="true"
but the outcome were the same (works in Android Studio, did not work on emulator/phone). Is there something that I missed out?