我正在使用libgdx在我的Android游戏项目中投放广告。我在网上看到了这个代码,它对我有用。问题是它显示顶部的通知栏,广告的位置位于屏幕的左下角,这会遮挡角色的视图。游戏处于横向位置,我想将广告放在底部中心部分。如何取消通知栏并将广告放在正确的位置。我是java的新手,我不懂这段代码。谢谢。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
cfg.useGL20 = false;
//setContentView(R.layout.main);
RelativeLayout layout = new RelativeLayout(this);
RelativeLayout.LayoutParams gameViewParams =
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
//gameViewParams.bottomMargin = 150;
requestWindowFeature( Window.FEATURE_NO_TITLE );
View gameView = initializeForView(new ZBGame(), cfg);
layout.addView(gameView, gameViewParams);
AdView adView = new AdView(this);
adView.setAdUnitId("YOUR ADMOB AD ID");
//adView.setAdUnitId("app-id");
adView.setAdSize(AdSize.BANNER);
RelativeLayout.LayoutParams adParams =
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
layout.addView(adView, adParams);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
setContentView(layout);
答案 0 :(得分:-1)
我还没有做到这一点,但我认为你会为adParams添加另一条规则以使视图居中。
例如:
adParams.addRule(RelativeLayout.CENTER_HORIZONTAL);