Admob ad not resizing correctly upon screen orientation [Includes Pictures](Admob 广告在屏幕方向上未正确调整大小 [包括图片])
问题描述
我在我的应用中使用 Admob 投放广告,但遇到了问题.每当我将屏幕切换到横向模式时,广告就会出现,但它的大小与纵向模式下的大小相同.在我将清单中的这个 xml 声明添加到我的主要活动中后发生了这个问题,这是保持应用程序主要部分顺利运行所必需的:
I am using Admob for ads in my app and I ran into a problem. Whenever I turn the screen to landscape mode, the ad shows up but it's the same size as it was in portrait mode. This problem occured after I added this xml declaration in my manifest to my main activity that was necessary to keep the main parts of the app functioning smoothly:
android:configChanges="orientation|keyboardHidden|screenSize"
我在我的广告中使用智能横幅的尺寸:
I am using smart banner in my ad for the size:
ads:adSize="SMART_BANNER"
我已经附上了这个问题的图片:
I have attached pictures of this problem:
我必须做些什么才能让广告在横向模式下正确调整大小而不删除
What do I have to do to get the ad to resize properly in landscape mode without deleting
android:configChanges="orientation|keyboardHidden|screenSize"
在我的主要活动的清单中?
in the manifest for my main activity?
推荐答案
与其他响应一致(但更新到当前的 AdMob SDK -v7.5-,并提供完整代码),onConfigurationChanged() 方法该活动需要包括广告视图的销毁和创建:
In line with other responses (but updating them to the current AdMob SDK -v7.5-, and providing the full code), the onConfigurationChanged() method of the activity needs to include the destruction and creation of the Ad View:
// Remove the ad keeping the attributes
AdView ad = (AdView) myactivity.findViewById(R.id.adView);
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) ad.getLayoutParams();
LinearLayout parentLayout = (LinearLayout) ad.getParent();
parentLayout.removeView(ad);
// Re-initialise the ad
ad.destroy();
ad = new AdView(parent);
ad.setAdSize(com.google.android.gms.ads.AdSize.SMART_BANNER);
ad.setAdUnitId(myactivity.getString(R.string.banner_ad_unit_id));
ad.setId(R.id.adView);
ad.setLayoutParams(lp);
parentLayout.addView(ad);
// Re-fetch add and check successful load
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice(parent.getString(R.string.test_device_id))
.build();
这篇关于Admob 广告在屏幕方向上未正确调整大小 [包括图片]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Admob 广告在屏幕方向上未正确调整大小 [包括图片]
基础教程推荐
- 如何强制对超级方法进行多态调用? 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01