Admob 横幅已隐藏
Posted
技术标签:
【中文标题】Admob 横幅已隐藏【英文标题】:Admob banner hidden 【发布时间】:2014-03-07 20:06:35 【问题描述】:我能够将来自 Libgdx 和 Google play 的代码放在一起以添加来自 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();
【问题讨论】:
尝试使用不同的 AdSize,例如AdSize.SMART_BANNER
问题不在于大小,而是横幅隐藏在游戏屏幕(Splash 和游戏中的任何其他屏幕)后面我需要将横幅视图放在前面
【参考方案1】:
已解决查看编辑代码,将 LayoutParams 添加到游戏视图中
【讨论】:
【参考方案2】:我找到了: 我只需要改变
adView.setAdSize(AdSize.FULL_BANNER);
到
adView.setAdSize(AdSize.BANNER);
【讨论】:
公开发布您的邮件地址是相当冒险的。让垃圾邮件机器人很容易捡起它。以上是关于Admob 横幅已隐藏的主要内容,如果未能解决你的问题,请参考以下文章
如何检查 webview YouTube 视频播放器是不是已启动