简体   繁体   English

Admob 横幅位置错误

[英]Admob banner wrong position

I have a android game written with JAVA, for some unknown reason, Admob banner is displayed in wrong position on small percentage of our players devices, I have already tested it on 30+ devices, but could not reproduce it, some players sent us proofs though.我有一个用 JAVA 编写的 android 游戏,不知什么原因,Admob 横幅在我们的一小部分玩家设备上显示在错误的位置,我已经在 30 多台设备上进行了测试,但无法重现它,一些玩家向我们发送了证明尽管。

By design, our banner should ALWAYS be displayed in TOP RIGHT corner of the screen, but sometimes its getting displayed in TOP LEFT, any idea will be greatly appreciated.按照设计,我们的横幅应该始终显示在屏幕的右上角,但有时它会显示在左上角,任何想法将不胜感激。

That's how I initialise it (I am doing everything programatically, no xml's这就是我初始化它的方式(我正在以编程方式做所有事情,没有 xml

    @Override
    protected void onSetContentView()
    {
        final RelativeLayout relativeLayout = new RelativeLayout(this);

        final FrameLayout.LayoutParams relativeLayoutLayoutParams = new FrameLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);

        this.mRenderSurfaceView = new RenderSurfaceView(this);
        this.mRenderSurfaceView.setRenderer(this.mEngine, this);

        final android.widget.RelativeLayout.LayoutParams surfaceViewLayoutParams = new RelativeLayout.LayoutParams(BaseGameActivity.createSurfaceViewLayoutParams());
        surfaceViewLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);

        relativeLayout.addView(this.mRenderSurfaceView, surfaceViewLayoutParams);

        FrameLayout frameLayout = new FrameLayout(this);

        FrameLayout.LayoutParams fparams=new FrameLayout.LayoutParams( FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);

        adView = new AdView(this);

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

        adView = new AdView(this);
        adView.setAdSize(com.google.android.gms.ads.AdSize.BANNER);
        adView.setAdUnitId("....");
        adView.setEnabled(false);
        adView.refreshDrawableState();
        adView.setVisibility(AdView.GONE);
        AdRequest adRequest = new AdRequest.Builder().build();
        adView.loadAd(adRequest);
        adView.refreshDrawableState();

        frameLayout.addView(adView,adViewLayoutParams);

        relativeLayout.addView(frameLayout,fparams);

        this.setContentView(relativeLayout, relativeLayoutLayoutParams);
    }

Show/hide methods:显示/隐藏方法:

public void hideBanner()
    {
        if (adDisplayed)
        {
            this.runOnUiThread(new Runnable()
            {
                @Override
                public void run() {
                    adView.setEnabled(false);
                    adView.setVisibility(View.INVISIBLE);
                    adDisplayed = false;
                }
            });
        }
    }

    public void showBanner()
    {
        if (!ResourcesManager.getInstance().isNoAdverts())
        {
            if (!adDisplayed)
            {
                this.runOnUiThread(new Runnable()
                {
                    @Override
                    public void run()
                    {
                        AdRequest adRequest = new AdRequest.Builder().build();
                        adView.loadAd(adRequest);

                        adView.setAdListener(new com.google.android.gms.ads.AdListener()
                        {
                            @Override
                            public void onAdLoaded()
                            {
                                adView.setVisibility(View.GONE);
                                adView.setEnabled(true);
                                adView.setVisibility(AdView.VISIBLE);
                            }
                        });

                        adDisplayed = true;
                    }
                });
            }
        }
    }

Here are my project settings:这是我的项目设置:

    compileSdkVersion 28
    minSdkVersion 16
    targetSdkVersion 28

This issue was reported from players with SDK: 23此问题是由使用 SDK 的玩家报告的:23

Given that the problem was reported by a user in Israel, I suspect that the user has their device's language set to a right-to-left language, like Hebrew.鉴于该问题是由以色列用户报告的,我怀疑该用户将其设备的语言设置为从右到左的语言,例如希伯来语。

Since you are using Gravity.END , this will place the element on the left side of the device in this scenario (since, after all, that is the "end" for this user).由于您使用的是Gravity.END ,因此在这种情况下,这会将元素放置在设备的左侧(毕竟,这该用户的“结束”)。 If you want the element to always be on the right, regardless of the normal layout direction for your user's chosen language, build your LayoutParams with Gravity.RIGHT instead.如果您希望元素始终位于右侧,而不管用户所选语言的正常布局方向如何,请Gravity.RIGHT构建LayoutParams

Alternatively, you could disable right-to-left support for your application.或者,您可以禁用应用程序的从右到左支持 Check the <application> tag in your AndroidManifest.xml and delete this attribute:检查AndroidManifest.xml<application>标记并删除此属性:

android:supportsRtl="true"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM