【发布时间】:2014-06-02 15:00:23
【问题描述】:
我正在使用 Andengine 并想添加一个 Admob 横幅。我找到了这段代码,它运行良好。但是使用此代码,LayoutParams 至少需要 API 19。我想变得更低,比如说 8 或类似的东西。我可以用什么代替?
@Override protected void onSetContentView() {
// CREATING the parent FrameLayout //
final FrameLayout frameLayout = new FrameLayout(this);
// CREATING the layout parameters, fill the screen //
final FrameLayout.LayoutParams frameLayoutLayoutParams =
new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT);
// CREATING a Smart Banner View //
adView = new AdView(this);
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId("ca-app-pub-2181015300018417/9550656088");
// Doing something I'm not 100% sure on, but guessing by the name //
adView.refreshDrawableState();
adView.setVisibility(AdView.VISIBLE);
// ADVIEW layout, show at the bottom of the screen //
final FrameLayout.LayoutParams adViewLayoutParams =
new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT,
Gravity.CENTER_HORIZONTAL|Gravity.BOTTOM);
// REQUEST an ad (Test ad) //
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("AB38B36BA72798C94A9C9329007FD4B0")
.build();
adView.loadAd(adRequest);
// RENDER the add on top of the scene //
this.mRenderSurfaceView = new RenderSurfaceView(this);
mRenderSurfaceView.setRenderer(mEngine, this);
// SURFACE layout ? //
final android.widget.FrameLayout.LayoutParams surfaceViewLayoutParams =
new FrameLayout.LayoutParams(super.createSurfaceViewLayoutParams());
// ADD the surface view and adView to the frame //
frameLayout.addView(this.mRenderSurfaceView, surfaceViewLayoutParams);
frameLayout.addView(adView, adViewLayoutParams);
// SHOW AD //
this.setContentView(frameLayout, frameLayoutLayoutParams);
} // onSetContentView() 结束 //
【问题讨论】:
-
阅读文档。只有 1 个构造函数是 api19,其余的都是 api 1。你可能并不真的需要那个构造函数。
-
根据文档,它不需要 api 19。只有一个构造函数需要 api 19 ,只需使用另一个构造函数。
-
我用了另一个,现在效果很好。谢谢大家!
标签: java android admob andengine