Android: how to display admob ads on GLSurfaceView

房东的猫 提交于 2019-12-05 20:27:53

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>

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);
}

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!