Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 584
naxrohan Avatar asked Dec 23 '22 07:12

naxrohan


1 Answers

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);
    }
});
like image 179
earthw0rmjim Avatar answered Jan 12 '23 23:01

earthw0rmjim