对景观的android admob的大小调整景观、大小、android、admob

2023-09-13 23:56:32 作者:入戏太深

我已经宣布AdMob的清单上像

 <活动
           机器人:名称=com.google.ads.AdActivity
          android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
          />
 

这是正常大小时,设备rotacion,但现在我必须补充安卓configChanges =keyboardHidden |定位来的活动,包括为了AdMob的,以prevent活动重装。我达到了,但现在的AdMob不会缩放时的风景线。 onConfigChanges事件现在我可以强迫的AdMob被调整适当的景观尺寸。怎么样?谢谢你。

  @覆盖
    公共无效onConfigurationChanged(配置NEWCONFIG){
      super.onConfigurationChanged(NEWCONFIG);
    }
 

解决方案

我面临同样的问题,但发现了一个解决方法。

我的AD浏览坐在该页面的底部,一相对布局内。加载时它看起来是正确的,所以我承担了的LayoutParams 是正确的。要解决这个问题,我不得不删除一切从 RelativeLayout的,创建一个新的AD浏览报,并添加这一切早在正确的顺序,与原的LayoutParams

是这样的:

  @覆盖
公共无效onConfigurationChanged(配置NEWCONFIG){
    super.onConfigurationChanged(NEWCONFIG);

    AD浏览报AD浏览报=(AD浏览报)findViewById(R.id.adView);
    查看contentFrame = findViewById(R.id.contentFrameLayout);

    RelativeLayout的父=(RelativeLayout的)adView.getParent();
    的LayoutParams mapFrameParams = contentFrame.getLayoutParams();
    的LayoutParams adViewParams = adView.getLayoutParams();

    parent.removeView(AD浏览报);
    parent.removeView(contentFrame);

    AD浏览报newAdView =新的AD浏览报(这一点,AdSize.SMART_BANNER,的getString(R.string.admob_pubId));

    newAdView.setId(R.id.adView);

    parent.addView(newAdView,adViewParams);
    parent.addView(contentFrame,mapFrameParams);
    newAdView.loadAd(新AdRequest());
}
 
安卓和苹果的界面设计之尺寸规范

这对我的作品,但仍然感觉就像一个黑客攻击。

I have declared adMob on manifest like

<activity 
           android:name="com.google.ads.AdActivity"
          android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
          />

It is resized properly when device rotacion but now I must add android:configChanges="keyboardHidden|orientation" to activity that contains adMob in order to prevent activity reloading. I am reaching it but now adMob is not scaled when landscape. onConfigChanges event I could now force adMob to be resized with proper landscape dimensions. How? thank you.

@Override
    public void onConfigurationChanged(Configuration newConfig) {
      super.onConfigurationChanged(newConfig);
    }

解决方案

I faced the same problem, but found a work-around.

My AdView sits at the bottom of the page, inside of a Relative layout. It looks correct when loaded, so I assumed the LayoutParams were correct. To fix this issue, I had to remove everything from the RelativeLayout, create a new AdView, and add it all back in the correct order, with the original LayoutParams.

Something like:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    AdView adView = (AdView)findViewById(R.id.adView);
    View contentFrame = findViewById(R.id.contentFrameLayout);

    RelativeLayout parent = (RelativeLayout) adView.getParent();
    LayoutParams mapFrameParams = contentFrame.getLayoutParams();
    LayoutParams adViewParams = adView.getLayoutParams();

    parent.removeView(adView);
    parent.removeView(contentFrame);

    AdView newAdView = new AdView(this, AdSize.SMART_BANNER, getString(R.string.admob_pubId));

    newAdView.setId(R.id.adView);

    parent.addView(newAdView, adViewParams);
    parent.addView(contentFrame,mapFrameParams);
    newAdView.loadAd(new AdRequest());
}

This works for me, but still feels like a hack.