Q:

How to make TableLayout vertically center in ConstraintLayout with something below it?

I'm trying to create a TableLayout and AdMob component inside ConstraintLayout. I want to make the tablelayout to be in center of the screen vertically and the ads component to be at the end. My code is follows,
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".relax.LevelsUX">
     <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">
           <TableLayout
              android:id="@+id/relax_level_ux_TL"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:gravity="center"
              android:stretchColumns="*">
            </TableLayout>

            <com.google.android.gms.ads.AdView
              android:id="@+id/relax_gameplay_adView"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_gravity="center_horizontal|bottom"
              app:adSize="BANNER"
              app:adUnitId="ca-app-pub-3940256099942544/6300978111">
            </com.google.android.gms.ads.AdView> 
     </LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

But the problem is the ads component is not visible, as I'm giving android:layout_height="match_parent" for TableLayout. Now, when I make the android:layout_height="wrap_content" for TableLayout, the layout is going on the top of the screen. I can't give it a fixed height, as I'm adding rows dynamically.
How can I solve this problem?

A:

Make tablelayout height 0dp, with layout_weight=1 , It will work.
       <TableLayout
          android:id="@+id/relax_level_ux_TL"
          android:layout_width="match_parent"
          android:layout_height="0dp"
          android:layout_weight="1"
          android:gravity="center"
          android:stretchColumns="*">
        </TableLayout>

