简体   繁体   English

ListView阻止Admob广告

[英]ListView blocking Admob Ad

I have the following XML file which corresponds to a ListActivity: 我有以下与ListActivity对应的XML文件:

<?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: 我从ListActivity中调用此Java代码:

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. 当我查看XML文件的图形布局时,似乎广告横幅恰好位于ListView的顶部。 However, when I run my actual app, the ListView seems to take up the entire screen, likely blocking the ad. 但是,当我运行实际的应用程序时,ListView似乎占据了整个屏幕,可能会阻塞广告。 Anyone know what's wrong? 有人知道怎么了吗?

The problem is that your ListView has layout_height="fill_parent". 问题是您的ListView具有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. 而是让它wrap_content并使用layout_weight =“ 1”告诉它消耗任何未使用的空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM