4

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?

wojciii
  • 4,253
  • 1
  • 30
  • 39
Paul Hunnisett
  • 898
  • 1
  • 17
  • 36

2 Answers2

14

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).

Yoni Samlan
  • 37,905
  • 5
  • 60
  • 62
  • Brilliant - thanks. I can't believe that I've got this far without clicking about what the orientation was for... doh! – Paul Hunnisett Dec 07 '10 at 16:46
  • 1
    I have lost countless hours of my life to the fact that there's a default attribute for `orientation`, and it's not the one you'd expect. It's one of those parameters that you should really have to specify explicitly, and the default behavior of `horizontal` is out of keeping with 80% of the times it's actually used (as vertical), leading to all sorts of unexpected behaviors. I still get bitten by this one every once in a while when I forget that. – Yoni Samlan Dec 07 '10 at 21:09
  • this worked to properly layout the UI, however, as soon as an Ad is shown the listview scrolls all the way to the bottom of the data. How can I prevent the listview from scrolling to the bottom of the data ? – Someone Somewhere Nov 27 '12 at 23:40
  • `android:transcriptMode` should be disabled :-) now it's no longer scrolling – Someone Somewhere Nov 27 '12 at 23:59
0

Also, the Admob AdView does not display if it could not retrieve an ad. Check your LogCat to see if there are any AdMobSDK messages in there. You may need to add one house ad to your account to make sure it is working.

I would also put a layout_weight=1 on the AdView, maybe also try layout_height="wrap_content" on the ListView.

shammer64
  • 213
  • 1
  • 9