Admob on surfaceview

萝らか妹 提交于 2019-12-04 19:36:43

In your activity's onCreate:

// Add admob ads.
admobView = new AdView(this, AdSize.BANNER, "YOUR_UNIT_ID");
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
    RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
admobView.setLayoutParams(lp);

RelativeLayout layout = new RelativeLayout(this);
layout.addView(surfaceView);
layout.addView(admobView);
admobView.loadAd(new AdRequest());

setContentView(layout);

IN the example above, "surfaceView" is your surfaceView instance, that you should instantiate like you do today. Don't forget to call admobView.destroy() in your activity's onDestroy.

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