AdMob AdView 仅以横向显示

发布于 2024-10-14 20:25:54 字数 958 浏览 7 评论 0原文

好吧,我已经无计可施了。正在开发使用 AdMob 的 Android 应用。一切都按照他们的说明进行设置,没有错误等。

问题是:我仅在手机横向时才能看到广告。

我已经在网上搜索并完成了我能想到的所有最后一件事来测试它:

  • 在测试模式和正常模式下尝试
  • 从我的主要活动的清单及其代码中的处理程序中删除了方向configChanges,以防它们导致它
  • 删除了所有应用程序的功能,以便 onCreate 看起来像上面的说明中的那样
  • 尝试了主布局的所有可能的更改 - 将其放置在不同的位置,删除其他小部件,不同的布局等

这些只是几个小时测试的总结,每个时间结果是一样的。纵向不显示广告,横向显示广告(如预期的那样 - 未拉伸,但最大宽度问题是众所周知的,不是问题)。

Logcat 显示一切在两个方向都正常工作:发出请求,返回广告。我可以点击横向显示的广告,但点击它们应该纵向显示的区域没有任何作用。

这让我精神不振!有什么想法吗?

编辑:好的,问题已经解决了,但恐怕我不能真正称之为“修复”。我记得广告在以前但类似的应用中运行良好。它使用的是不同版本的 AdMob SDK - 我不知道任何细节,但 admob-sdk-android.jar 是 77kb 而不是 136kb。

我将 77kb 的文件以及 attrs.xml 文件从旧应用程序复制到新应用程序中,这需要将 AdView 中的 PrimaryTextColor 属性更改为 textColor,仅此而已。现在可以完美运行 - 而且作为奖励,广告也可以在横向视图中水平延伸到整个屏幕!

我将其发布为编辑而不是答案,因为它似乎更合适,而且我仍然想知道是否有人可以阐明这个问题。是 AdMob SDK 问题吗?

Ok, I'm officially at my wit's end here. Working on an Android app that uses AdMob. Everything is set up to the letter following their instructions, no errors, etc.

Problem is: I only see ads when the phone is in landscape orientation.

I've searched online and done every last thing I can think of to test this:

  • Tried it in test mode and normal mode
  • Removed the orientation configChanges from my main activity's manifest and their handlers in the code, in case they were causing it
  • Removed all functionality of the app so that onCreate looked like the one in the instructions above
  • Tried every possible change of main layout - placing it in different locations, removing other widgets, different layouts, etc

These are just a summary of a few hours of testing, every time the result is the same. Portrait shows no ad, landscape shows the ad (as/where expected - not stretched, but the max width issue is well known and not a problem).

Logcat shows everything to be working properly in both orientations: Requests are made, ads are returned. I can click on the ads that appear in landscape, but tapping the area they're meant to be in portrait does nothing.

It's driving me mental! Any ideas?

Edit: Okay, the problem is gone but I'm afraid I can't really call it a "fix". I remembered ads working fine in a previous but similar app. It was using a different version of the AdMob SDK - I don't know any details, but admob-sdk-android.jar is 77kb rather than 136kb.

I copied the 77kb one from the old app into the new app, along with the attrs.xml file, which necessitated changing the primaryTextColor attribute in the AdView to textColor, and that's it. Works perfectly now - and as a bonus, the ads stretch horizontally across the whole screen in landscape view as well!

I'm posting this as an edit rather than an answer since it seems more appropriate and I'd still love to know if anyone can shed some light on the issue. Was it an AdMob SDK issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

牵强ㄟ 2024-10-21 20:25:54

我也遇到这个问题,你应该检查父容器是否有padding,如果有,去掉padding,突然就会出现广告。我觉得这不太合逻辑,但有帮助。

I also encountered this issue, you should check if the parent container is padded, if it is, remove padding and all of sudden ads will appear. I don't find it very logical but it helps.

祁梦 2024-10-21 20:25:54

不确定这是否有帮助,但我遇到了类似的问题,在横向游戏中,广告只会以纵向模式显示。在选项卡 2 上,我从某人那里借来进行测试。结果发现设备上有某种屏幕锁定导致了这种情况。花了几个小时试图追查这个错误。

Not sure if this will help, but i had a similar issue, where in a landscape game, the ads would appear in portrait mode only. On a tab 2 i borrowed for testing from someone. Turned out there was some sort of screen lock on the device which caused it. Spent hours trying to chase the bug down.

山色无中 2024-10-21 20:25:54

检查此布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context=".AddTest"
    tools:ignore="MergeRootFrame" >

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_ad_unit_id" 
        >
    </com.google.android.gms.ads.AdView>

</RelativeLayout>

我在工具中遇到同样的问题:ignore =“aaaaaaaaa”和填充

Check this layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context=".AddTest"
    tools:ignore="MergeRootFrame" >

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_ad_unit_id" 
        >
    </com.google.android.gms.ads.AdView>

</RelativeLayout>

I have same problem in tools:ignore = "aaaaaaaaa" and padding

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文