Namita
Namita

Reputation: 75

Placing admob ads below a listview

I want to place an adMob AdView at the bottom of the screen. But the ads overlap on the ListView last item and I can't see the last item of the ListView very well. If i use android:layout_below="@+id/list_view". The ads doesn't load!

How can I place the ListView just above the AdView?

 <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <ListView
            android:id="@+id/list_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:scrollingCache="false"
            android:animationCache="false"
            android:smoothScrollbar="true"
            android:stretchMode="columnWidth">
        </ListView>


        <com.google.android.gms.ads.AdView
            android:id="@+id/adView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/list_view"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            ads:adSize="SMART_BANNER"
            ads:adUnitId="@string/ads_banner">
        </com.google.android.gms.ads.AdView>


    </RelativeLayout>

Upvotes: 0

Views: 1851

Answers (3)

Ankitkumar Makwana
Ankitkumar Makwana

Reputation: 3485

Make your xml like:

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

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

    <ListView
        android:id="@+id/list_view"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:animationCache="false"
        android:gravity="center"
        android:scrollingCache="false"
        android:smoothScrollbar="true"
        android:layout_above="@+id/adViewCardItem"
        android:stretchMode="columnWidth" >
    </ListView>
</RelativeLayout>

Upvotes: 5

Abhishek Agarwal
Abhishek Agarwal

Reputation: 1897

It should work perfectly

  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <ListView
        android:id="@+id/list_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:scrollingCache="false"
        android:animationCache="false"
        android:smoothScrollbar="true"
        android:stretchMode="columnWidth">
    </ListView>


    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="SMART_BANNER"
        android:layout_weight="0"
        ads:adUnitId="@string/ads_banner">
    </com.google.android.gms.ads.AdView>


</LinearLayout>

Upvotes: 1

MPG
MPG

Reputation: 795

hey you can try some thing like this

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

<com.google.android.gms.ads.AdView
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/adViewCardItem"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@id/list_view"
    ads:adSize="BANNER"
    ads:adUnitId="@string/ads_banner">
</com.google.android.gms.ads.AdView>

<ListView
    android:id="@+id/list_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:animationCache="false"
    android:gravity="center"
    android:paddingBottom="150dip"
    android:scrollingCache="false"
    android:smoothScrollbar="true"
    android:stretchMode="columnWidth" >
</ListView>

Upvotes: 0

Related Questions