2012-01-17 22 views
0

AdMob広告の読み込みに失敗した場合、アプリに組み込まれている自分の広告(ImageView)を表示するレイアウトを作成しようとしています。 リストビューを私の広告を隠さないようにすることはできません。ListView、AdMob、組み込みバックアップ広告レイアウトの問題

AdMob広告だけを使用しても問題はありません。

enter image description here

は、ここに私のレイアウトです。

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

+0

を試してみましたhttp://stackoverflow.com/questions/5878283/android-admob-not-showing-linearlayout-on -bottom – kosa

+0

@thinksteepそれは私が思うに役立ちません。私はRelativeLayoutを持っているので、私はlayout_weightを使うことはできません.LinearLayoutへの変更が大きな苦痛になることを恐れています。 – mbwasi

答えて

0

これはまさにあなたが望むものです。
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> 
+0

おかげさまで、あなたのレイアウトはうまくいきました。 AdMobのonReceivedAdとonFailedToReceiveAdの可視性を制御しています。 – mbwasi

0

私はこれを実装するためのクリーンな方法は、最初にあなたのcom.google.ads.AdViewビューを保持しているコンポーネントを持っているだろうと思います。その後、広告が読み込まれなかったことに気がついたら、ImageViewでその広告をスワップできます。

さらに優れたもの:それをカスタムコンポーネントにします。したがって、このコンポーネントのインスタンスを含む「外部」(レイアウト)から、このコンポーネントは、AdMob広告の読み込みに失敗したかどうかによって、AdMobの広告を表示するか、独自の広告を表示することによって実装されます。

関連する問題