【发布时间】:2015-07-04 08:04:01
【问题描述】:
我正在使用 andengine,我想展示 admob 广告,但我的应用程序崩溃代码在扩展 basegameactivity 的主要活动中:
//代码
public class GameActivity extends BaseGameActivity
@Override
protected void onSetContentView() {
adAdmob = (AdView)findViewById(id.admob_adView);
if(adAdmob != null){
return;
}
//layout for andengine
final FrameLayout frameLayout = new FrameLayout(this);
final FrameLayout.LayoutParams frameLayoutLayoutParams =
new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT);
final FrameLayout.LayoutParams adViewLayoutParams =
new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.WRAP_CONTENT,
Gravity.CENTER_HORIZONTAL|Gravity.BOTTOM);
//AdRequest ad = new AdRequest(null);
//adview
adAdmob = new AdView(this);
adAdmob.setAdSize(AdSize.BANNER);
adAdmob.setAdUnitId("ca-app-pub-7376050471332410");
//AdRequest ad = new AdRequest.Builder().build();
adAdmob.setAdListener(new AdListener() {
public void onAdLoaded()
{
}
}
);
adAdmob.loadAd(new AdRequest.Builder().build());
this.mRenderSurfaceView = new RenderSurfaceView(this);
mRenderSurfaceView.setRenderer(mEngine,this);
final android.widget.FrameLayout.LayoutParams surfaceViewLayoutParams =
new FrameLayout.LayoutParams(super.createSurfaceViewLayoutParams());
frameLayout.addView(this.mRenderSurfaceView, surfaceViewLayoutParams);
frameLayout.addView(adAdmob, adViewLayoutParams);
this.setContentView(frameLayout, frameLayoutLayoutParams);
}
【问题讨论】:
-
请清楚地表达您的问题并编辑代码的第一行。
-
@renzo 我的应用工作正常,但是当我使用 admob 代码时它崩溃了