首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >安卓:如何在GLSurfaceView上显示广告

安卓:如何在GLSurfaceView上显示广告
EN

Stack Overflow用户
提问于 2012-10-02 19:30:23
回答 1查看 2.1K关注 0票数 3

我目前能够在ui view上获得广告(在单独的测试项目中),但我想在GLSurfaceView中显示此广告。我尝试在活动的onCreate( )方法中加载广告,并在屏幕的present方法(所有渲染都已完成)中调用

MyGameActivity.mAdView.bringToFront();//我想它会把广告带到所有游戏对象的前面。

现在,在运行该项目时,我可以在logcat窗口Recieved ad url "big url"中看到消息,但我看不到屏幕上的广告。在我的游戏中,只有一个活动和许多游戏屏幕。请帮我弄清楚如何在游戏屏幕上显示广告。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-10-03 01:11:17

您应该将您的布局修改为如下所示:

代码语言:javascript
复制
<?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>

这是我的代码,它不言自明:

代码语言:javascript
复制
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);
}

正确完成后,您将从google play教程中获得等同于BannerEssentials教程的应用程序,但使用的是GLSurfaceView。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12689484

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档