【问题标题】:admob ads do not show upadmob 广告不显示
【发布时间】:2019-06-09 19:12:52
【问题描述】:

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

我已经阅读了一些相关的问题,但对于我正在使用的 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>

【问题讨论】:

    标签: android admob ads


    【解决方案1】:

    当您使用应填充广告的活动/方法时检查您的 logCat。我遇到了一个无法显示的问题,因为横幅需要 50dip 垂直空间,而我只给它 50px(不是同一件事)。 LogCat 会向您发出警告,指出它无法放入请求的空间。

    还有,你在打电话吗

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

    在您的活动中某处?您必须请求广告,它们不会自动加载。

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

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

        将 admob 设置为测试帐户。然后您将能够查看是 Admob 问题还是您的代码问题。

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

        【讨论】:

        • 我已将其设置为测试帐户。 request.setTesting(true);当我运行/调试我的应用程序时,我确实看到我的 admod 帐户不时收到新请求。我如何检查 logcat?
        • 在 Eclipse 的 DDMS 视图中查看 logcat 选项卡。
        【解决方案4】:

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

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

        然后我设置了一个虚假的内部广告(我稍后会制作一个广告来购买该应用的非广告版本)。

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

        希望对你有帮助

        【讨论】:

          【解决方案5】:

          等待 30 分钟对我有用。我重新启动了应用程序,添加出现了。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2015-05-10
            • 2020-11-13
            相关资源
            最近更新 更多