我在我的应用程序中使用 Admob 来转换广告,但遇到了问题。每当我将屏幕转到横向模式时,广告就会显示,但它的大小与纵向模式下的大小相同。在我将 list 中的这个 xml 声明添加到我的主要 Activity 后发生了这个问题,这是保持应用程序的主要部分顺利运行所必需的:

android:configChanges="orientation|keyboardHidden|screenSize"

我在我的广告中使用智能横幅的尺寸:
ads:adSize="SMART_BANNER"

我附上了这个问题的图片:


我该怎么做才能让广告在横向模式下正确调整大小而不删除
android:configChanges="orientation|keyboardHidden|screenSize"

在我的主要 Activity 的 list 中?

最佳答案

这就是我解决它的方法:

@Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        orientation_changed = true;
        renewAd();
    }

    private void renewAd() {
        AdView ad = (AdView) findViewById(R.id.adView);
        LayoutParams lp = (LayoutParams) ad.getLayoutParams();
        // change relative layout for your layout which contains the adView
        RelativeLayout parent = (RelativeLayout) ad.getParent();
        parent.removeView(ad);
        AdView newAd = new AdView(this, AdSize.SMART_BANNER, "YOUR ID");
        newAd.setId(R.id.adView);
        newAd.setLayoutParams(lp);
        parent.addView(newAd);
        newAd.loadAd(new AdRequest());
    }

问候

关于java - Admob 广告无法根据屏幕方向正确调整大小 [包括图片],我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20929963/

10-09 05:30
查看更多