我使用AndEngine创建了一个仅使用一个View的应用程序,即游戏本身。 它扩展了SimpleBaseGameActivity,但我的问题出现在所有这些上:
我在互联网上找到的每个例子都不起作用,原因非常相似。以下示例来自
http://www.andengine.org/forums/tutorials/admob-xml-layout-example-t3338.html#p15852
@Override
protected void onSetContentView() {
final FrameLayout frameLayout = new FrameLayout(this);
final FrameLayout.LayoutParams frameLayoutLayoutParams =
new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT,
FrameLayout.LayoutParams.FILL_PARENT);
final AdView adView = new AdView(this, AdSize.BANNER, "xxxxxxxxxxxx");
adView.refreshDrawableState();
adView.setVisibility(AdView.VISIBLE);
final FrameLayout.LayoutParams adViewLayoutParams =
new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT,
Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL);
// getHeight returns 0
// http://groups.google.com/group/admob-pu ... a874df3472
int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50,
getResources ().getDisplayMetrics ());
// top of AD is at middle of the screen
adViewLayoutParams.topMargin = height/2;
AdRequest adRequest = new AdRequest();
adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
adView.loadAd(adRequest);
this.mRenderSurfaceView = new RenderSurfaceView(this);
mRenderSurfaceView.setRenderer(mEngine);
final android.widget.FrameLayout.LayoutParams surfaceViewLayoutParams =
new FrameLayout.LayoutParams(super.createSurfaceViewLayoutParams());
frameLayout.addView(this.mRenderSurfaceView, surfaceViewLayoutParams);
frameLayout.addView(adView, adViewLayoutParams);
this.setContentView(frameLayout, frameLayoutLayoutParams);
}
另请查看a screenshot from eclipse了解详情。
当我声称我发现的所有25个示例因新版本而被弃用时,我是否正确?
答案 0 :(得分:1)
这些方法来自" old" admob API将很快被弃用。现在,admob与Google Play游戏服务集成。因此,您需要删除admob库,并使用新的API:https://developers.google.com/mobile-ads-sdk/docs/?hl=es