naxrohan
naxrohan

Reputation: 372

AdView overlaps last item of RecyclerView

overlapped list item

I hope the attached screenshot make my issue clear, The the last item in the RecyclerView list is getting overlapped by the AdView.

Adding bottom padding & margin to the RecyclerView, leaves a blank space at the bottom behind the AdView, this is undesirable.

Is there any way to set over-scroll or offset to the scrolling ?

Any quick solutions/suggestion would be helpful, Thanks in advance.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rvProverbs"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:spanCount="4"
        />

    <com.google.android.gms.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="@string/ad_unit_id">
    </com.google.android.gms.ads.AdView>


</RelativeLayout>

Upvotes: 4

Views: 1131

Answers (3)

earthw0rmjim
earthw0rmjim

Reputation: 19427

The height of banners with the attribute adSize="BANNER" is 50 dp.

The simplest solution might be to add an 50 dp (or greater) bottom padding to your RecyclerView and set clipToPadding to false:

<android.support.v7.widget.RecyclerView
    android:id="@+id/rvProverbs"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="50dp"
    android:clipToPadding="false"
    app:spanCount="4" />

In case your AdView has a dynamic height (or you would like to add the padding only when the AdView is loaded), you just have to set the padding dynamically as well, from code.

For example:

adView.setAdListener(new AdListener() {
    @Override
    public void onAdLoaded() {
        recyclerView.setPadding(0, 0, 0, adView.getHeight());
        // recyclerView.setClipToPadding(false);
    }
});

Upvotes: 8

user4571931
user4571931

Reputation:

Try this code ..

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<android.support.v7.widget.RecyclerView
    android:id="@+id/rvProverbs"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:spanCount="4"
    android:layout_above="@+id/adView2"
    android:layout_marginBottom="10dp"

    />

<com.google.android.gms.ads.AdView
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/adView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    ads:adSize="BANNER"
    ads:adUnitId="@string/ad_unit_id">
</com.google.android.gms.ads.AdView>

Upvotes: 1

Jay Rathod
Jay Rathod

Reputation: 11255

User android:layout_above="" property inside RecyclerView and give id of AdView to .

Like

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rvProverbs"
        android:layout_width="match_parent"
        android:layout_above="@+id/adView2"
        android:layout_height="match_parent"
        app:spanCount="4"
        />

    <com.google.android.gms.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="@string/ad_unit_id">
    </com.google.android.gms.ads.AdView>


</RelativeLayout>

Upvotes: 1

Related Questions