Android的:如何显示在GLSurfaceView AdMob的广告 [英] Android: how to display admob ads on GLSurfaceView

查看:145
本文介绍了Android的:如何显示在GLSurfaceView AdMob的广告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前能获得 UI视图(在不同的测试项目)的AdMob的广告,但我想展示该广告的 GLSurfaceView 。 我试图加载在的onCreate广告()活动,并在present我的屏幕的方法(所有渲染完成的)我叫方法

I am currently able to get the admob ads on ui view (in separate test project ), but i want to display this ad in GLSurfaceView . I tried to load the ad in onCreate( ) method of activity and in present method of my screen (where all rendering is done) i called

MyGameActivity.mAdView.bringToFront(); //以为它会带来的广告在所有的游戏对象的前面。

MyGameActivity.mAdView.bringToFront(); //thought it will bring the ad in front of all the game objects.

现在运行的项目中,我可以看到的logcat窗口中的消息:收到的广告URL大网址 但我不能在屏幕上看到的广告。在我的游戏,只有一个活动,众多的游戏画面。请帮我弄清楚如何我的游戏屏幕上显示的广告。

now on running the project i can see the message in logcat window Recieved ad url "big url" but i cant see the ad on screen. In my game there is only one activity and many game screens. please help me figure out how to display ads on my game screen.

推荐答案

您应该修改您的布局是这样的:

You should modify your layout to be something like this:

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

这是我的code,这是自我解释的:

This is my code, which is self explanatory.:

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代替。

After you get this right you will get the equivalent to the BannerEssentials tutorial app from the google play tutorials, but using GLSurfaceView instead.

这篇关于Android的:如何显示在GLSurfaceView AdMob的广告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆