Centralise TableLayout in ScrollView

71 views Asked by At

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: enter image description here

But on the emulator, the text is not centralized: enter image description here

I have tried 2 things:

  1. wrap TableLayout with a LinearLayout
  2. 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?

0

There are 0 answers