2011-05-01 206 views
0

我已成功将我的admob广告显示在Google提供的示例代码http://code.google.com/mobile/ads/docs/android/fundamentals.html上,但是当涉及到我自己的应用程序时,它们不显示。admob广告未显示

我已阅读了一些相关的问题,但对于我正在使用的LinearLayout而言似乎没有问题。有一点需要注意的是,在我的应用程序中,它扩展了ListActivity而不是Activity。

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:ads="http://schemas.android.com/apk/res/com.mypackage.myapp" 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="2"> 

     <com.google.ads.AdView android:id="@+id/adView"       
      android:layout_width="wrap_content"       
      android:layout_height="fill_parent"       
      ads:adUnitId="myadmobid"       
      ads:adSize="BANNER"/> 
    </LinearLayout> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="2"> 
     <TextView 
      android:id="@+id/hottopictab" 
      android:text="Deal" 
      android:gravity="center_horizontal|center_vertical" 
      android:background="#000000" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:textStyle="bold" 
     android:typeface ="sans" 
      android:layout_weight="1"/> 

     <TextView 
      android:id="@+id/newtopictab" 
      android:text="()" 
      android:gravity="center_horizontal|center_vertical" 
      android:background="#000000" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:textStyle="bold" 
     android:typeface ="sans" 
      android:layout_weight="1"/> 

     <TextView 
      android:id="@+id/recommendtab" 
      android:text="" 
      android:gravity="center_horizontal" 
      android:background="#000000" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:layout_weight="1"/> 

    <ImageButton 
      android:layout_height="fill_parent" 
      android:id="@+id/refresh" 
      android:background="#000000" 
      android:src="@drawable/refresh"  
      android:layout_width="wrap_content" 
      android:layout_marginRight="6dip"  
     /> 


    </LinearLayout>    
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="40"> 

     <ListView 
      android:id="@android:id/list" 
      android:text="row one" 
      android:textSize="15pt" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"/> 

    </LinearLayout>  
</LinearLayout> 

回答

2

问题解决了。这是由于没有足够的空间“没有足够的空间来显示广告!想要:< 480,75>,具有:< 336,522>”。当我放大我的模拟器时,它可以工作。

1

将admob设置为测试帐户。然后,您将能够看到它是否是Admob问题或代码问题。

此外,请检查Logcat - 可能是目前没有任何广告可供您使用。

+0

我已将它设置为测试帐户。 request.setTesting(真);我确实发现当我运行/调试我的应用程序时,我的admod帐户不时收到新的请求。但我如何检查logcat? – Yang 2011-05-01 05:15:07

+0

查看Eclipse中DDMS视图中的logcat选项卡。 – Haphazard 2011-05-01 12:29:05

4

当您在应该填充您的广告的活动/方法时,请检查您的logCat。我有一个问题,它不会显示,因为横幅需要50dip的垂直空间,我只给它50px(不一样的东西)。 LogCat会给你一个警告,说它不适合请求的空间。

而且,你叫

AdView adView = (AdView)this.findViewById(R.id.adView); 
     adView.loadAd(new AdRequest()); 

在您的活动的地方?您必须申请广告,但不会自动加载。

另一件事,在您的布局中放置广告,您需要确保您有像adMob教程所示的attrs.xml文件。

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <declare-styleable name="com.google.ads.AdView"> 
     <attr name="adSize"> 
      <enum value="1" name="BANNER"/> 
      <enum name="IAB_MRECT" value="2"/> 
      <enum name="IAB_BANNER" value="3"/> 
      <enum name="IAB_LEADERBOARD" value="4"/> 
     </attr> 
     <attr format="string" name="adUnitId"/> 
    </declare-styleable> 
</resources> 
0

我几个小时前实施Admob时遇到了这个问题。

我所做的就是进入我的admob帐户,并设置应用程序为未填充广告资源提供“内部广告”。

然后我建立了一个假的内部广告(即时让后者制作广告来购买非广告版本的应用)。

这意味着,如果您从应用中向admob请求广告并且目前没有需求,则会显示您的内部广告。

希望这会有帮助

0

只等30分钟为我工作。我重新启动了应用程序,添加出现了。