Search code examples
androidadmobbanner-adssmartbanner

Ad Mob Smart Banner does not work for all devices


I have a layout in which I have a grid view and I want to show banner ad at the bottom of screen I have following code

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout

    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/backgroundColor"
    android:fitsSystemWindows="true">

    <include layout="@layout/detail_activity_bar"></include>

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
            <GridView xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/home_grid"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:horizontalSpacing="5dp"
                android:verticalSpacing="5dp"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:layout_marginTop="5dp"
                android:layout_marginBottom="60dp"
                android:numColumns="2"
                android:stretchMode="columnWidth"/>

        <com.google.android.gms.ads.AdView
            xmlns:ads="http://schemas.android.com/apk/res-auto"
            android:id="@+id/adViewGallery"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="5dp"
            android:layout_gravity="bottom|center"
            ads:adSize="SMART_BANNER"
            ads:adUnitId="@string/home_banner">
        </com.google.android.gms.ads.AdView>
    </FrameLayout>


</android.support.design.widget.CoordinatorLayout>

It works well with 4'' mobile devices but on bigger devices banner ad overlap the grid content. How can I make it generic for all devices so that it does not overlap with app content


Solution

  • try below layout

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        android:weightSum="1"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#29000000"
        android:orientation="vertical"
        android:fitsSystemWindows="true">
        <include layout="@layout/detail_activity_bar"></include>
    
            <GridView
                android:layout_weight="0.9"
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/home_grid"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:horizontalSpacing="5dp"
                android:verticalSpacing="5dp"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:layout_marginTop="5dp"
                android:numColumns="2"
                android:stretchMode="columnWidth"/>
            <com.google.android.gms.ads.AdView
                android:layout_weight="0.1"
                xmlns:ads="http://schemas.android.com/apk/res-auto"
                android:id="@+id/adViewGallery"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_marginBottom="5dp"
                android:layout_gravity="bottom|center"
                ads:adSize="SMART_BANNER"
                ads:adUnitId="@string/home_banner">
            </com.google.android.gms.ads.AdView>
    </LinearLayout>