How to show Admob in SurfaceView

六眼飞鱼酱① 提交于 2019-12-23 04:45:42

问题


I try to show Admob on my SurfaceView.

  1. I use framework from book beginning android games from Mario Zechner
  2. In framework there is a class (AndroidFastRenderView extends SurfaceView implements Runnable) and in that class there is line canvas.drawBitmap(framebuffer, null, dstRect, null); where framebuffer is Bitmap where is all drawn in game.
  3. In that framework there is a class (AndroidGame extends Activity) where is line setContentView(renderView);

Here renderView is AndroidFastRenderView that is SurfaceView, Now I try to add Admob but I don't no how.

I can create Admob like this

AdView adView = new AdView(this, AdSize.BANNER, "MyID");

but where to add that view

Thanks for help.


回答1:


AdMob's Ad Catalog sample application has an example similar to this. In the above example, the AdView was defined in XML. But at a high level, you'll probably want something like this:

<RelativeLayout ...>
    <AdView ...
        android:id="@+id/adView"
        android:layout_alignParentBottom="true"/>
    <AndroidFastRenderView ...
        android:layout_above="@id/adView"/>
</RelativeLayout>

Where the AdView sits at the top or bottom outside of the AndroidFastRenderView. If you're doing it in code, I'd suggest you create a RelativeLayout, add the AdView as a subView of the RelativeLayout at the bottom (for example), and then add the renderView as a subView of the RelativeLayout, but above the AdView.



来源:https://stackoverflow.com/questions/10505185/how-to-show-admob-in-surfaceview

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