我能够将来自Libgdx和Google的代码放在一起来添加来自adMob的广告,但我似乎无法将横幅放在游戏屏幕的顶部,横幅只会在我触及后面底部并退出应用时显示
我的代码如下 任何帮助将不胜感激
Android主类
public class MainActivity extends AndroidApplication {
static AdView adView;
private static final String AD_UNIT_ID = "my id";
AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RelativeLayout layout = new RelativeLayout(this);
//cfg.useGL20 = false;
//initialize(new GameActivity(), false);
// Do the stuff that initialize() would do for you
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
View gameView = initializeForView(new GameActivity(), true);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("my device")
.build();
adView = new AdView(this);
adView.setAdSize(AdSize.FULL_BANNER);
adView.setAdUnitId(AD_UNIT_ID);
adView.loadAd(adRequest);
RelativeLayout.LayoutParams gameParams =
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
gameParams.bottomMargin = 1;
layout.addView(gameView, gameParams);
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_TOP);
layout.addView(adView, adParams);
setContentView(layout);
}
@Override
protected void onDestroy() {
if (adView != null) {
adView.destroy();
}
super.onDestroy();
}
@Override
protected void onPause() {
if (adView != null) {
adView.pause();
}
super.onPause();
}
@Override
protected void onResume() {
if (adView != null) {
adView.resume();
}
super.onResume();
}
}
答案 0 :(得分:0)
解决了看编辑的代码,将LayoutParams添加到游戏视图
答案 1 :(得分:-2)
我找到了: 我只需要改变
adView.setAdSize(AdSize.FULL_BANNER);
到
adView.setAdSize(AdSize.BANNER);