【问题标题】:error with advertising using admob使用 admob 做广告时出错
【发布时间】:2014-01-02 02:30:31
【问题描述】:

我在使用 google admob 时出错。手机屏幕大于 4" 时一切正常,但如果小于 4",则不会显示广告。在模拟器上我收到此错误

空间不足,无法展示广告!想要:,你

这是我的代码

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads">

<com.google.ads.AdView
android:id="@+id/lytMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="id"
ads:loadAdOnCreate="true" />

这是java代码

lytMain = (LinearLayout) findViewById(R.id.lytMain);
adView = new AdView(this, AdSize.BANNER, "Num google");
lytMain.addView(adView);
adView.bringToFront();
adView.loadAd(new AdRequest());

在屏幕为 4" 的 android 2.3 中不起作用:/ 仅适用于 4" 以上的屏幕和 4.0 以上的 android

我编辑了代码,现在看到这个错误

The following classes could not be instantiated:
- com.google.ads.AdView (Open Class, Show Error Log)
See the Error Log (Window > Show View) for more details.


java.lang.ClassNotFoundException: org.json.JSONException
    at java.net.URLClassLoader$1.run(    at java.net.URLClassLoader$1.run(    at java.security.AccessController.doPrivileged(    at java.net.URLClassLoader.findClass(    at java.lang.ClassLoader.loadClass(    at java.lang.ClassLoader.loadClass(    at com.google.ads.AdView.a(SourceFile:184)
    at com.google.ads.AdView.a(SourceFile:352)
    at com.google.ads.AdView.<init>(SourceFile:125)

【问题讨论】:

  • 请为AdSize.BANNER留出至少 320x50px 的空间。

标签: android admob


【解决方案1】:

您需要在垂直和水平方向上留出足够的空间来展示广告。您需要更改布局,以便在所有设备和屏幕尺寸上都有足够的空间(错误消息中列出)。

横幅尺寸在Admob page 上列出。如果是AdSize.BANNER,则为 320x50。

【讨论】:

  • 我现在改变布局为广告创造更多空间,没有错误连续看 LinearLayout android:id="@+id/lytMain" android:layout_width="320dp" android:layout_height="50dp " android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_centerHorizo​​ntal="true" android:orientation="vertical" />
  • 但是考虑到布局的其他元素,你真的提供了那么多空间吗?
  • 发布所有布局,什么都没有:/布局很小,什么都没有
  • 你可以在没有其他元素的空活动中尝试吗?
  • 等我删除按钮看看发生了什么
【解决方案2】:

最好使用RelativeLayout 包装AdView。这是我使用 BANNER Admob 的工作配置。

在我的 XML 文件中,我将广告包装在 RelativeLayout 中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/layout" >
<com.google.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    ads:adSize="BANNER"
    ads:adUnitId="youradsid"
    ads:loadAdOnCreate="true" />

</RelativeLayout>

【讨论】:

    【解决方案3】:

    您需要在布局中添加 com.google.ads.AdView 元素。如果您使用的是 LinearLayout,请使用重力为其提供足够的空间以满足最小空间标准。请记住,广告中的图片和文字需要屏幕上的最小空间。

    我建议您使用高级别的RelativeLayout,并覆盖 com.google.ads.AdView 元素底部中心。这样一来,无论您如何定位,您的某些内容都会被广告覆盖。

    【讨论】:

    • 制作宽度、填充父级并检查。
    • 没有发送此错误 没有足够的空间来展示广告!想要:,拥有:
    • 不明白。请改写。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-11
    • 1970-01-01
    • 1970-01-01
    • 2021-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多