我正在使用libgdx和AdMob。我无法将广告置于屏幕底部的中心位置。在当前的设置中,我将它放在屏幕的左下角,但它不会居中。
我的MainActivity中的代码
// Add the AdMob view
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_LEFT);
adParams.addRule(RelativeLayout.CENTER_IN_PARENT);
layout.addView(adView, adParams);
答案 0 :(得分:8)
// Add the AdMob view
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_LEFT);
adParams.addRule(RelativeLayout.CENTER_IN_PARENT);
layout.addView(adView, adParams);
这很有效。
答案 1 :(得分:0)
for libgdx将此代码粘贴到onCreate()
中的ur android类中layout = new RelativeLayout(this); adView =新AdView(此广告,AdSize.BANNER,adMObid);
View gameView=initializeForView(new TalkingFriendApp(this), cfg);
RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
adParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
RelativeLayout.LayoutParams adParams1 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
adParams1.addRule(RelativeLayout.ALIGN_PARENT_CENTER);
adView.loadAd(new AdRequest());
layout.addView(gameView, adParams);
layout.addView(adView, adParams1);
setContentView(layout);