【发布时间】:2014-06-03 07:40:46
【问题描述】:
我正在使用PublisherAdView 在我的应用中显示横幅广告。当应用程序启动时,我创建 PublisherAdView,将其添加到布局中,然后请求广告。我想在方向更改后显示已请求的相同广告。目前 PublisherAdView 在方向更改时被销毁并重新创建,因此我丢失了所请求的广告。
这是我在片段中创建 PublisherAdView 的方法:
PublisherAdView banner_ad_view = new PublisherAdView(getActivity());
banner_ad_view.setAdUnitId(ad_unit_id);
banner_ad_view.setAdSizes(new AdSize(ad_width, ad_height));
这是我将 PublisherAdView 添加到我的片段布局的方法:
int id = R.id.fragment_banner_ad_container;
RelativeLayout ad_container = (RelativeLayout) fragment_view.findViewById(id);
ad_container.addView(banner_ad_view);
这是我将广告加载到 PublisherAdView 中的方法(使用 PublisherAdRequest):
banner_ad_view.loadAd(ad_request);
我一直在努力避免使用android:configChanges,因为我确实有不同的资源需要根据方向进行管理。
非常感谢任何帮助!
【问题讨论】:
标签: android android-layout android-fragments ads android-orientation