Android的 - Admob的 - 加载广告,然后改变的可视性导致问题 [英] Android - Admob - Loading ad then changing visibility causes problems

查看:340
本文介绍了Android的 - Admob的 - 加载广告,然后改变的可视性导致问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

长版:我有一个Android游戏。在每一个画面我展示的广告,但游戏画面本身 - 在这里你真正发挥。现在,如果你启动应用程序,游戏(广告开始加载),然后点击开始前的广告加载完毕 - 它不会被显示时,它应该是(它只有一点点带)

短版:调用 AdView.loadAd ,然后调用 AdView.setVisibility(View.INVISIBLE) 广告收到如果我们调用将产生一个奇怪的结果之前, AdView.setVisibility(View.VISIBLE) 广告被加载

这会发生:

相反的,例如:

现在,点击这个小条左边是还是算作点击广告 - 点击它做什么,点击广告会做(启动浏览器,这样的......)

和你应该回到主屏幕(IE点击home键),然后返回到应用程序,广告被认为是回来了,因为它应该。

有没有人encouter它,没有任何人有任何想法如何解决呢?谢谢你。

编辑:下面是相关code:

创建广告的看法:

  this.mAdView =新的AD浏览报(这一点,AdSize.BANNER,XXXXXXXXXXXXX);
 

创建布局PARAMS:

 最后FrameLayout.LayoutParams adViewLayoutParams =
            新FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
                    FrameLayout.LayoutParams.WRAP_CONTENT,
                    Gravity.TOP | Gravity.CENTER_HORIZONTAL);
 

创建根视图组,其布局PARAMS:

 最后的FrameLayout的FrameLayout =新的FrameLayout(本);
最后FrameLayout.LayoutParams frameLayoutLayoutParams =
            新FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT,
                    FrameLayout.LayoutParams.FILL_PARENT);
 

添加到根视图组:

  frameLayout.addView(this.mAdView,adViewLayoutParams);
 

而最终,设置内容视图:

  this.setContentView(的FrameLayout,frameLayoutLayoutParams);
 

解决方案

我设法解决它通过这种方式:

  1. 在这改变了知名度的方法,我第一次检查是在广告加载。如果不是,我不改变的可见性:

  2. 设置AdListener为AD浏览报。在onReceivedAd方法,我检查病情隐藏它 - 如果它应该被隐藏,我躲

工程罚款这种方式。

Long version: I have an Android game. In each "screen" I'm showing the ads BUT the game screen itself - where you actually play. Now, if you launched the app-game (ad begins to load) and then clicked on "Start" before the ad has finished loading - it won't be shown when it should be (only a little strip of it)

Short version: Calling AdView.loadAd and then calling AdView.setVisibility(View.INVISIBLE) before the ad was received will yield a weird result if we call AdView.setVisibility(View.VISIBLE) after the ad is loaded.

This happens:

Instead of, for example:

Now, clicking on this tiny strip left is still counted as clicking on the ad - clicking on it does whatever clicking on the ad would do (launching the browser and such...)

And should you go back to the home screen (I.E click the home button) then get back to the application, the ad is seen back again as it should.

Did anyone encouter it, and does anyone have any idea how to solve it? Thanks.

EDIT: Here is the relevant code:

Creating the ad view:

this.mAdView = new AdView(this, AdSize.BANNER, "xxxxxxxxxxxxx");

Creating the layout params:

final FrameLayout.LayoutParams adViewLayoutParams =
            new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
                    FrameLayout.LayoutParams.WRAP_CONTENT,
                    Gravity.TOP | Gravity.CENTER_HORIZONTAL);

Creating the root view group, and its layout params:

final FrameLayout frameLayout = new FrameLayout(this);
final FrameLayout.LayoutParams frameLayoutLayoutParams =
            new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT,
                    FrameLayout.LayoutParams.FILL_PARENT);

Adding to the root view group:

frameLayout.addView(this.mAdView, adViewLayoutParams);

And eventually, setting content view:

this.setContentView(frameLayout, frameLayoutLayoutParams);

解决方案

I have managed to solve it in this way:

  1. In the method which changes the visibility, I first check is the ad was loaded. If it was not, I don't change the visibility:

  2. Set an AdListener for the AdView. in the onReceivedAd method, I check the condition to hide it - if it should be hidden, I hide.

Works fine this way.

这篇关于Android的 - Admob的 - 加载广告,然后改变的可视性导致问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆