Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't seem to display both a ListView and an AdView at the same time

I have an Activity in my app that simply displays some results from a search. This data is displayed using a ListView. This works well. I recently tried adding an Adview underneath it, but it simply doesn't display. What's more, it pushes my List View up to the top of the screen so that it can only occupy the top 20% or so of the screen - with only blank underneath.

Here is the display XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:myapp="http://schemas.android.com/apk/res/uk.co.redfruit.android.whogotwhat"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingTop="10dp"
    android:paddingBottom="10dp"
    >
    <ListView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:id="@+id/scanResults"
        android:paddingLeft="5dp" 
        android:paddingRight="5dp" 
        />
    <com.admob.android.ads.AdView 
        android:id="@+id/ad"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        myapp:backgroundColor="#000000"
        myapp:primaryTextColor="#FFFFFF"
        myapp:secondaryTextColor="#CCCCCC" 
        />
</LinearLayout>

What am I missing here?

like image 312
Paul Hunnisett Avatar asked Dec 09 '22 12:12

Paul Hunnisett


1 Answers

For starters, use android:orientation="vertical" on your LinearLayout, or it'll default to being a horizontal one. Secondly, try setting the LinearLayout's height to fill_parent and set your ListView height to 0px but with a layout_weight of 1. If it's still not behaving, I'd guess admob's AdView is behaving badly and ignoring the wrap_content directive -- try fixing its height to a specific size in dip (Admob ought to tell you what the sizes are that they'll be serving up there, anyways).

like image 61
Yoni Samlan Avatar answered Mar 29 '23 23:03

Yoni Samlan