Search code examples
androidlistviewadview

Why can't I place an Adview after a ListView?


I'm testing an Adview on my layout. If I place the Adview before the ListView everything is fine but if I place it after the ListView it just doesn't show up.

What's wrong?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/android:list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="bottom"
        android:background="@android:color/white" />

    <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="xxxx"
        ads:testDevices="xxxx" />

</LinearLayout>

Solution

  • You set the ListView's layout_height to fill_parent, so it will take all the remaining vertical space in the layout. Your AdView is there, it was just displaced out of the screen by the ListView.

    If you want to place the AdView at the bottom, and have the ListView take all the remaining vertical space, you can do it with weights:

    <ListView
        android:id="@+id/android:list"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="@android:color/white" />