I have the following XML file which corresponds to a ListActivity:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/classview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="xxxx" >
</com.google.ads.AdView>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
And I call this Java code from within the ListActivity:
public void setupAd(){
AdRequest adRequest = new AdRequest();
adRequest.addTestDevice("xxxx");
AdView adView = (AdView) findViewById(R.id.adView);
adView.loadAd(adRequest);
}
When I look at the graphical layout of my XML file, it seems to neatly have the ad banner on top of the ListView. However, when I run my actual app, the ListView seems to take up the entire screen, likely blocking the ad. Anyone know what's wrong?
The problem is that your ListView has layout_height="fill_parent".
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
Instead have it wrap_content and use layout_weight="1" to tell it to consume any unused space.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.