2012-10-02 32 views
3

我目前能夠在ui view(在單獨的測試項目中)獲得admob廣告,但我想在GLSurfaceView中顯示此廣告。 我試圖加載廣告活動中的onCreate()方法,在我的屏幕的本發明的方法(其中所有的渲染完成後)我叫Android:如何在GLSurfaceView上顯示admob廣告

MyGameActivity.mAdView.bringToFront(); //認爲它會將廣告帶到所有遊戲對象的前面。

現在運行該項目,我可以在logcat窗口中看到消息Recieved ad url "big url" 但我無法在屏幕上看到廣告。在我的遊戲中,只有一個活動和許多遊戲畫面。請幫我弄清楚如何在我的遊戲屏幕上顯示廣告。

+0

你的佈局是什麼樣的? –

+0

我設置在java代碼中的佈局不是xml文件,下面是代碼 AdView mAdView = new AdView(this,AdSize.BANNER,「id」); FrameLayout layout = new FrameLayout(this); //(FrameLayout)this.findViewById(R.id.adViewLayout);我們可以使用FrameLayout.LayoutParams來創建一個新的FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,FrameLayout.LayoutParams.WRAP_CONTENT,android.view.Gravity.BOTTOM | android.view.Gravity.CENTER_HORIZONTAL); \t layout.addView(GLGame.mAdView,adsParams); \t mAdView.loadAd(new AdRequest()); – appdroid

+1

你把你的GLSurfaceView添加到同一個FrameLayout中嗎?如果是的話,你可以發佈該代碼。如果你不是那麼這就是你的問題。 –

回答

1

你應該修改你的佈局是這樣的:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/layoutMain" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" >  
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/layout1" 
     android:tag="trueLayout" 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     >  
    </RelativeLayout> 
</LinearLayout> 

這是我的代碼,這是自我解釋:

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState);   

    setContentView(R.layout.main); 

    LinearLayout layoutMain = (LinearLayout) findViewById(R.id.layoutMain); 

    // Create the adView 
    // Please replace MY_BANNER_UNIT_ID with your AdMob Publisher ID 
    adView = new AdView(this, AdSize.BANNER, "YourPersonalID#"); 

    layoutMain.addView(adView); 

    // Initiate a generic request to load it with an ad 
    AdRequest request = new AdRequest(); 
    request.setTesting(true); 

    adView.loadAd(request);  

    RelativeLayout layout1 = (RelativeLayout) findViewById(R.id.layout1); 
    layout1.setOnTouchListener(this); 

    mTestHarness = new GLSurfaceView(this); 
    mTestHarness.setEGLConfigChooser(false); 
    mTestHarness.setRenderer(this); 
     mTestHarness.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);  

    layout1.addView(mTestHarness); 
} 

你得到這個權利之後,您將獲得相當於從谷歌播放教程的BannerEssentials教程應用程序,但使用GLSurfaceView代替。

+0

感謝您的回答,我完成了,現在我的應用程序準備啓動.. :) – appdroid