androidandroid-recyclerviewadmobadview

Android RecyclerView with AdView- best practices AdMob


I'm finishing my first mobile application and I want to add some AdViews at the bottom of the views. I read the AdMob policies but I'm still not sure is that the right way of ad presentation. I have a recycler view and ad on the bottom. User is scrolling down but the ad is still visible, at the end of the view I add extra 50dp padding to fit the ad with the last item so it's not overlaying it. RecyclerView items are not clickable so it won't be a miss click for ad. Is that a good way or I have to change it? Screenshot for a better explanation.

recyclerview

last item in recyclerview


Solution

  • You ensure that your ad does not overlap with content using LinearLayouts and layout_weight something like this.

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/backgroundColor"
        android:orientation="vertical"
        android:layout_weight="1"
        android:fitsSystemWindows="true">
    
        <include layout="@layout/detail_activity_bar"></include>
    
        <SomeView xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/home_grid"
            android:layout_weight="0.9"
            android:layout_width="match_parent"
            android:layout_height="0dp"/>
    
    
        <com.google.android.gms.ads.AdView
            xmlns:ads="http://schemas.android.com/apk/res-auto"
            android:id="@+id/adViewGallery"
            android:layout_weight="0.1"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_gravity="center"
            ads:adSize="BANNER"
            ads:adUnitId="@string/home_banner">
        </com.google.android.gms.ads.AdView>
    </LinearLayout>
    

    adSize BANNER suits well for most of the devices, while SMART_BANNER does overlap with bigger screen mobiles as per my experience.

    with above implementation you will never get admob banner policy violations