问题
I try to show Admob on my SurfaceView.
- I use framework from book beginning android games from Mario Zechner
- 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.
- 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