I have an activity which has a surfaceview capturing whole screen. i want to put an admob ad on surfaceview. I found this link but it does not work. Any idea ?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.
文章来源: Admob on surfaceview