gpt4 book ai didi

java - 在游戏 View 下添加 admob

转载 作者:行者123 更新时间:2023-11-30 11:47:45 25 4
gpt4 key购买 nike

我一直在尝试将 admob 置于我的游戏 View 下方。

这是我的代码

public class HoodStarGame extends AndroidApplication {
@Override public void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create the layout
RelativeLayout layout = new RelativeLayout(this);

// 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);

// Create the libgdx View
View gameView = initializeForView(new HoodStar(), false);

// Create and setup the AdMob view
AdRequest request = new AdRequest();
request.addTestDevice(AdRequest.TEST_EMULATOR);
request.addTestDevice("7ADDEC88A42947CD1FD7F2EC2F527485");

AdView adView = new AdView(this, AdSize.BANNER, "a14f19c2fe8d9e0"); // Put in your secret key here
adView.loadAd(request);

// Add the libgdx view
layout.addView(gameView);

// Add the AdMob view
RelativeLayout.LayoutParams adParams =
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

layout.addView(adView, adParams);

// Hook it all up
setContentView(layout);
}

但是,当运行此广告时,广告会显示在底部游戏屏幕的顶部

我该如何解决这个问题?

最佳答案

你错过了真实的adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);

您很可能希望为 gameLayoutParams 设置边距:

gameLayoutParams.bottomMargin = 55;//无论高度是多少

关于java - 在游戏 View 下添加 admob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9165263/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com