androidadview

adview at bottom of the screen


I want to get my adView at bottom of the screen but nothing works for me. How can I do that?

<?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=".MainActivity">

    <WebView
        android:id="@+id/webView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />


    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"

        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_gravity="bottom"
        android:layout_weight="1"
        app:adSize="BANNER"
        app:adUnitId="ca-app-pub-XXX"

        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/webView"></com.google.android.gms.ads.AdView>




</androidx.constraintlayout.widget.ConstraintLayout

>

It looks like your post is mostly code; please add some more details.


Solution

  • Use this config on your AdView:

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        ... />