2012-11-22 162 views
0

我在屏幕底部顯示一條橫幅。Relativelayout檢查橫幅廣告?

這是XML代碼:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/layoutAdView" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="50dp" 
    android:layout_alignParentBottom="true" 
    android:gravity="center_horizontal" > 
</RelativeLayout> 

有時我得到的廣告請求完成,但我沒有看到的一面旗幟。

如何檢查相對佈局?如果在相對佈局中顯示某些內容,那麼它應該讓我真正的其他錯誤。

+1

在主題沒有標籤:http://meta.stackexchange.com/questions/19190/should-questions-include-tags-in-他們的標題 –

回答

1

假設您使用的是Google Admob SDK,因爲您尚未指定所用的廣告服務器軟件。

您可以將AdListener附加到屏幕上的廣告空間,並在添加無法顯示時處理您想要執行的操作。

import android.content.Context; 
import android.util.Log; 
import android.widget.Toast; 

import com.google.ads.Ad; 
import com.google.ads.AdListener; 
import com.google.ads.AdRequest; 
import com.google.ads.AdRequest.ErrorCode; 

public class AdmobAdListener implements AdListener { 

    Context context; 
    AdRequest adRequest; 

    public AdmobAdListener(Context context, AdRequest adRequest) { 
     this.context = context; 
     this.adRequest = adRequest; 
    } 

    /** The log tag. */ 
    private static final String LOG_TAG = "AdmobAdListener"; 

    /** Called when an ad is clicked and about to return to the application. */ 
    public void onDismissScreen(Ad arg0) { 
     Log.d(LOG_TAG, "onDismissScreen"); 
     Toast.makeText(context, "onDismissScreen", 
     Toast.LENGTH_SHORT).show(); 

    } 

    /** Called when an ad was not received. */ 
    public void onFailedToReceiveAd(Ad ad, ErrorCode error) { 
     String message = LOG_TAG + " onFailedToReceiveAd (" + error + ")"; 
     Log.d(LOG_TAG, message); 
     Toast.makeText(context, message, Toast.LENGTH_SHORT).show(); 
     ad.loadAd(adRequest); 
    } 

    /** 
    * Called when an ad is clicked and going to start a new Activity that will 
    * leave the application (e.g. breaking out to the Browser or Maps 
    * application). 
    */ 
    public void onLeaveApplication(Ad ad) { 
     Log.d(LOG_TAG, "onLeaveApplication"); 
     Toast.makeText(context, "onLeaveApplication", Toast.LENGTH_SHORT).show(); 
    } 

    /** 
    * Called when an Activity is created in front of the app (e.g. an 
    * interstitial is shown, or an ad is clicked and launches a new Activity). 
    */ 
    public void onPresentScreen(Ad ad) { 
     Log.d(LOG_TAG, "onPresentScreen"); 
     Toast.makeText(context, "onPresentScreen", 
     Toast.LENGTH_SHORT).show(); 
    } 

    /** Called when an ad is received. */ 
    public void onReceiveAd(Ad ad) { 
     Log.d(LOG_TAG, "onReceiveAd"); 
     Toast.makeText(context, "onReceiveAd", Toast.LENGTH_SHORT).show(); 
    } 

} 

使用這個標籤在你的佈局XML文件

<com.google.ads.AdView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:id="@+id/adMob" 
     ads:adUnitId="abcdefghighlmnop123" 
     ads:adSize="BANNER"/> 
+0

我正在使用InMobi + AdMob。 AdMob很棒。完美的作品。問題在於InMobi。 – user1205415