2011-09-15 23 views
4

我无法解决这个错误,为我的生活。我已经看过谷歌和周围,没有解决方案的工作。我的广告似乎在Android 1.5和1.6版本上运行良好,但在版本2之上,我收到了该错误。“无法获得第一个布局后的viewWidth”错误

我已将广告放入LinearLayout中,这是滚动视图中的第一个布局。

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:orientation="vertical" 
    android:background="@drawable/bg_wallpaper" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 

    <LinearLayout 
     android:orientation="vertical" 
     android:id="@+id/drillactivity" 
     android:layout_width="fill_parent" 
     android:layout_gravity="bottom" 
     android:layout_height="340dp"> 

      <com.google.ads.AdView 
       android:id="@+id/adView" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       ads:adUnitId="my id goes here" 
       ads:adSize="BANNER" 
       ads:loadAdOnCreate="true"/> 

我没有在广告中使用我班的任何代码。我更喜欢只通过xml来完成。

回答

3

我有类似的黑屏警告。问题在于设备上有两个具有相同AdMob ID的不同应用程序。

我删除了第二个应用程序(错误地使用了相同的ID)并且问题消失了。

3

使用下面的代码,我修复了这个错误。

<com.google.ads.AdView 
android:id="@+id/adView" 
android:layout_width="320dp" 
android:layout_height="50dp" 
android:gravity="center" 
ads:adUnitId="my id goes here" 
ads:adSize="BANNER" 
ads:loadAdOnCreate="true"/> 

我没有这个错误的任何具体原因,它可能无法在任何情况下工作。

+0

loadAdOnCreate是做什么的?在我的情况下,它引起了以下警告:“loadAd在广告已加载时调用,因此中止。” –

+0

loadAdOnCreate将在onCreate中加载广告。因此,您不必在onCreate中单独发送广告请求。 – asish

0

在xml中声明一个线性/相对布局,在您的活动中进行排版。然后将活动设置为adView的侦听器。 像:

googleAdView = new AdView(Activity,AdSize.IAB_BANNER, ADMOB_SITE_ID); 
googleAdView.setAdListener(Activity); 
com.google.ads.AdRequest request = new com.google.ads.AdRequest(); 
this.adMobLayout.removeAllViews(); 
this.adMobLayout.addView(googleAdView); 
googleAdView.loadAd(request); 

这里adMobLayout是您在XML布局已宣布的布局。

相关问题