【问题标题】:ListView, AdMob and built in backup Ad Layout issueListView、AdMob 和内置备份广告布局问题
【发布时间】:2012-01-18 05:40:12
【问题描述】:

我要做的是构建一个布局,如果 AdMob 广告无法加载,它会显示我自己的一个广告 (ImageView),这些广告 (ImageView) 内置在应用程序中。 我似乎无法让列表视图不掩盖我的广告。

如果我只使用 AdMob 广告,让它工作没有问题。

这是我的布局。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bgdark"
android:orientation="vertical" >

<RelativeLayout
    android:id="@+id/actionbarLayout"
    android:layout_width="fill_parent"
    android:layout_height="@dimen/actionbar_height"
    android:layout_alignParentTop="true"
    android:layout_marginBottom="2dip"
    android:background="@drawable/actionbar_background" >

    //Top bar is here

</RelativeLayout>

<LinearLayout
    android:id="@+id/layoutAds"
    android:layout_width="match_parent"
    android:layout_height="50dip"
    android:background="#00FF00"
    android:layout_alignParentBottom="true"
    android:layout_centerVertical="true" >

    <ImageView
        android:id="@+id/ImageAlternativeAd"
        android:layout_width="wrap_content"
        android:layout_height="50dip"
        android:layout_gravity="center_vertical"
        android:src="@drawable/anad"
        android:visibility="visible" >
    </ImageView>

    <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        ads:adSize="BANNER"
        ads:adUnitId="123456abcd"
        ads:loadAdOnCreate="true"
        ads:testDevices="TEST_EMULATOR,CFFFFFFF9A836FD749F3EF439CD"
        android:visibility="visible" />
</LinearLayout>

<ListView
    android:id="@+id/listCategories"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@id/adView"
    android:layout_below="@id/actionbarLayout"
    android:cacheColorHint="#00000000" >
</ListView>

【问题讨论】:

  • 看看这个链接能不能帮到你stackoverflow.com/questions/5878283/…
  • @thinksteep 我认为这无济于事,我不能使用 layout_weight,因为我有一个 RelativeLayout 我担心更改为 LinearLayout 会很痛苦,如果一切都失败了,可能会考虑它。

标签: android android-layout admob


【解决方案1】:

这正是你想要的。
https://stackoverflow.com/a/5188181/563306

另外,你试过了吗,

<ListView
    android:id="@+id/listCategories"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@id/layoutAds"
    android:layout_below="@id/actionbarLayout"
    android:cacheColorHint="#00000000" >
</ListView>

【讨论】:

  • 谢谢,您的布局效果很好,只是将其 layout_bellow 设置错了。我正在控制 AdMob onReceivedAd 和 onFailedToReceiveAd 中的可见性,并且效果很好。
【解决方案2】:

我认为实现这一点的一种简洁方法是拥有一个最初保存您的 com.google.ads.AdView 视图的组件。然后,当您注意到您的广告没有加载时,您可以将其与您的 ImageView 即时交换。

更好的是:将其设为自定义组件。因此,从“外部”(您的布局)来看,您只是包含此组件的一个实例,而在内部,此组件是通过显示来自 AdMob 的广告或您自己的广告来实现的,具体取决于 AdMob 广告是否加载失败。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-11
    • 1970-01-01
    • 2018-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多