AdMob Native Advanced Ad with too much Whitespace sometimes

32 Views Asked by At

I want to include an AdMob Native Ad in my Android app, but with the test Ad Unit ID, one of the two displayed ads adds a lot of whitespace that I cannot remove even with a MaxHeight attribute. What am I doing wrong? Here's my misc_nativead.xml:

    <com.google.android.gms.ads.nativead.NativeAdView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/ad"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/innerConstraintLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            android:layout_marginTop="16dp"
            android:layout_marginBottom="16dp"
            android:layout_marginStart="16dp"
            android:layout_marginEnd="16dp">

            <ImageView
                android:id="@+id/ad_app_icon"
                android:layout_width="80dp"
                android:layout_height="80dp"
                android:layout_gravity="center_vertical"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toStartOf="parent"/>

            <TextView
                android:id="@+id/ad_headline"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="8dp"
                android:layout_marginEnd="8dp"
                android:fontFamily="@font/centr_semibold"
                android:textColor="?contrastingColor"
                android:textSize="24sp"
                android:textAlignment="textStart"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toEndOf="@+id/ad_app_icon"
                app:layout_constraintEnd_toEndOf="parent" />

        </androidx.constraintlayout.widget.ConstraintLayout>

        <com.google.android.gms.ads.nativead.MediaView
            android:id="@+id/ad_media"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingStart="16dp"
            android:paddingEnd="16dp"
            app:layout_constraintTop_toBottomOf="@+id/innerConstraintLayout"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"/>

    </androidx.constraintlayout.widget.ConstraintLayout>

</com.google.android.gms.ads.nativead.NativeAdView>

And here is how it is placed in my app:

            <FrameLayout
                android:id="@+id/nativeAd"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="32dp"
                android:layout_marginStart="32dp"
                android:layout_marginEnd="32dp"
                app:layout_constraintTop_toBottomOf="@id/activityIcon"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                android:background="@drawable/shape_textview"/>

I've turned on "Show Layout Bounds" in Developer Options to show, well, the layout bounds.

[Ad Media is correct size][] [Ad Media is too tall][]

0

There are 0 best solutions below