2013-08-27 134 views
0

我必须对应于ListActivity下面的XML文件:的ListView阻止AdMob广告

<?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> 

而且我把这种Java代码从ListActivity中:

public void setupAd(){ 
    AdRequest adRequest = new AdRequest(); 
    adRequest.addTestDevice("xxxx"); 
    AdView adView = (AdView) findViewById(R.id.adView); 
    adView.loadAd(adRequest); 


} 

当我看图形我的XML文件的布局,似乎整齐地在ListView顶部有广告横幅。但是,当我运行我的实际应用程序时,ListView似乎占据了整个屏幕,可能会阻止广告。任何人都知道什么是错的?

+0

你有没有尝试加载一个真正的添加与真正的ID? –

+0

你的'xml'是正确的,这可能是由于广告没有加载!你的**清单中有'internet' *权限*吗? –

+0

确定它不只是被加载。第一次在第一个广告出现之前可能需要几分钟时间,直到它没有占用任何空间。 – Magakahn

回答

0

问题是你的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" 
/> 

改为使用wrap_content并使用layout_weight =“1”告诉它消耗任何未使用的空间。