【问题标题】:Admob ads displaying over buttons on Jelly BeanAdmob 广告显示在 Jelly Bean 上的按钮上
【发布时间】:2012-09-04 04:24:57
【问题描述】:

当我注意到 Admob 广告 (Admob SDK 6.1.0) 显示在应用程序的按钮顶部时,我正在测试应用程序与 Jelly Bean 的兼容性。我使用的布局是:

        <ImageView android:id="@+id/line"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/spinner"
            android:maxWidth="350sp"
            android:layout_marginTop="5dip"
            android:layout_centerHorizontal="true"
            android:src="@drawable/line"/>
        <View android:id="@+id/ad" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:layout_below="@id/line"
            android:layout_marginTop="5dip"
            android:layout_marginBottom="5dip"/>
        <Button android:id="@+id/generate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/ad"
            android:layout_centerHorizontal="true"
            android:textStyle="bold"
            android:textColor="#000000"
            android:text="@string/generate"/>

当广告加载时,它会显示在按钮的顶部。在以前的 Android 版本(ICS 和更早版本)中,将加载广告并按下按钮以容纳广告。有谁知道如何在 Jelly Bean 上恢复此功能?谢谢!

【问题讨论】:

  • 粘贴快照看起来意味着不同
  • @Khan 截图在这里真的无济于事。它只是一个广告。它下面有一个按钮,但你不会从屏幕截图中知道。上面的 XML 代码更有帮助。
  • 我使用了相同的 sdk 并检查了 admob 我的 admob 在 2.2 模拟器或果冻豆模拟器中的对齐底部相同的结果我的 xml 视图包含标题、listview 和 admob 或者添加完整的 xml 代码并让我检查它
  • @Khan 感谢您的帮助。我在下面发布了我的解决方法作为答案。

标签: android admob android-4.2-jelly-bean


【解决方案1】:

我对这个问题的解决方案是实现 AdListener 接口,以便在加载广告时手动设置按钮的上边距。这会将按钮向下移动并防止它被广告覆盖。

@Override
public void onReceiveAd(Ad arg0) {      
    // Move the generate button down by the height of the ad on load
    MarginLayoutParams params = (MarginLayoutParams)generateBtn.getLayoutParams();
    params.topMargin = AdSize.BANNER.getHeightInPixels(this);
    generateBtn.setLayoutParams(params);
}

而且由于这个问题只发生在 Jelly Bean 上,所以只在 Jelly Bean 上运行时设置 AdListener

if(Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN)
    ad.setAdListener(this);

【讨论】:

  • fyi,在 onReceiveAd 中执行if 逻辑可能比决定添加侦听器更有用。如果您想在此回调中执行任何其他操作,则必须稍后再执行此操作。
  • 这是真的,我将来可能不得不这样做。但是,在这种情况下,我在想为什么还要添加一个对非 Jelly Bean 设备没有任何作用的侦听器呢?似乎效率有点低。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-09-23
  • 1970-01-01
  • 1970-01-01
  • 2019-04-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多