Skip to content Skip to sidebar Skip to footer

How To Place Adview Below The Recyclerview? Please See Details

I'm developing an app in which some data is getting loaded from Firebase and is shown in the RecyclerView. What I want is I want to show the AdView below the RecyclerView and for t

Solution 1:

You should use LinearLayout instead of RelativeLayout. In LinearLayout put ad at the bottom of the screen and let it occupy it's space and set layout_weight to your RecyclerView.

<LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"... ><android.support.v7.widget.RecyclerViewandroid:id="@+id/recycler_view"android:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"... /><android.support.v7.widget.CardViewandroid:id="@+id/card_ads"android:layout_width="match_parent"android:layout_height="wrap_content"... ><com.google.android.gms.ads.NativeExpressAdViewandroid:id="@+id/adView"android:layout_width="match_parent"android:layout_height="wrap_content"... /></android.support.v7.widget.CardView></LinearLayout>

And one more thing, don't set layout_height of AdView to match_parent, use wrap_content instead.

Solution 2:

Try to put your RecyclerView inside other layout, or just set layout_above="@id/card_ads"

I think the main problem is that you set in card_ads layout_below, but not tell recyclerview that it should be over the card_ads

<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:ads="http://schemas.android.com/apk/res-auto"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:id="@+id/recyclerView_parentLayout"android:layout_width="match_parent"android:layout_height="match_parent"android:paddingBottom="@dimen/activity_vertical_margin"android:paddingLeft="8dp"android:paddingRight="8dp"app:layout_behavior="@string/appbar_scrolling_view_behavior"tools:context="com.abc.xyz.MainActivity"tools:showIn="@layout/app_bar_main"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:layout_above="card_ads"android:orientation="vertical"><android.support.v7.widget.RecyclerViewandroid:id="@+id/recycler_view"android:layout_width="match_parent"android:layout_height="match_parent"android:clipToPadding="false"android:scrollbars="vertical"app:layout_behavior="@string/appbar_scrolling_view_behavior"/></LinearLayout><android.support.v7.widget.CardViewandroid:id="@+id/card_ads"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_below="@id/recycler_view"android:layout_marginBottom="10dp"android:layout_marginTop="10dp"app:cardElevation="2dp"app:cardUseCompatPadding="true"app:contentPaddingBottom="2dp"><com.google.android.gms.ads.NativeExpressAdViewandroid:id="@+id/adView"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_alignParentBottom="true"android:layout_centerInParent="true"ads:adSize="280x80"ads:adUnitId="ca-app-pub-***********/*********"></com.google.android.gms.ads.NativeExpressAdView></android.support.v7.widget.CardView></RelativeLayout>

I've add Admob on my App, you can check at Github

Edit:

I put match parent, see if it works

<android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clipToPadding="false"
            android:scrollbars="vertical"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

Solution 3:

Add framelayout as a main layout .Try this code .Put your adView insted of button .
<?xml version="1.0" encoding="utf-8"?><FrameLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:ads="http://schemas.android.com/apk/res-auto"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:id="@+id/recyclerView_parentLayout"android:layout_width="match_parent"android:layout_height="match_parent"android:paddingBottom="@dimen/activity_vertical_margin"android:paddingLeft="8dp"android:paddingRight="8dp"app:layout_behavior="@string/appbar_scrolling_view_behavior"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"><android.support.v7.widget.RecyclerViewandroid:id="@+id/recycler_view"android:layout_width="match_parent"android:layout_height="wrap_content"android:clipToPadding="false"android:scrollbars="vertical"app:layout_behavior="@string/appbar_scrolling_view_behavior"/><android.support.v7.widget.CardViewandroid:id="@+id/card_ads"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_below="@id/recycler_view"android:layout_marginBottom="10dp"android:layout_marginTop="10dp"app:cardElevation="2dp"app:cardUseCompatPadding="true"app:contentPaddingBottom="2dp"><com.google.android.gms.ads.NativeExpressAdViewandroid:id="@+id/adView"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_alignParentBottom="true"android:layout_centerInParent="true"ads:adSize="280x80"ads:adUnitId="ca-app-pub-***********/*********"></com.google.android.gms.ads.NativeExpressAdView></android.support.v7.widget.CardView></LinearLayout><Buttonandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_gravity="bottom"/></FrameLayout>

Solution 4:

Add this to your XML

 <android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/adView"
    android:scrollbars="vertical">
</android.support.v7.widget.RecyclerView>

Post a Comment for "How To Place Adview Below The Recyclerview? Please See Details"