android - How can I retain a PublisherAdView on an orientation change?
2021腾讯云限时秒杀,爆款1核2G云服务器298元/3年!(领取2860元代金券),
地址:https://cloud.tencent.com/act/cps/redirect?redirect=1062
2021阿里云最低价产品入口+领取代金券(老用户3折起),
入口地址:https://www.aliyun.com/minisite/goods
推荐:Android Screen Orientation Change (Screen Rotation) Example
原文见: http://techblogon.com/android-screen-orientation-change-rotation-example/#
I'm using a PublisherAdView to display a banner ad in my app. When the app starts I create the PublisherAdView, add it to a layout, and request an ad. I would like to display the same ad that has already been requested after an orientation change. Currently the PublisherAdView gets destroyed and recreated on an orientation change, so I lose the ad that was requested.
Here is how I create the PublisherAdView in a fragment:
PublisherAdView banner_ad_view = new PublisherAdView(getActivity());
banner_ad_view.setAdUnitId(ad_unit_id);
banner_ad_view.setAdSizes(new AdSize(ad_width, ad_height));
Here is how I add the PublisherAdView to my fragment layout:
int id = R.id.fragment_banner_ad_container;
RelativeLayout ad_container = (RelativeLayout) fragment_view.findViewById(id);
ad_container.addView(banner_ad_view);
Here is how I load an ad into the PublisherAdView (using PublisherAdRequest):
banner_ad_view.loadAd(ad_request);
I have been trying to avoid using android:configChanges
as I do have different resources to manage based on orientation.
Any help is much appreciated!
android android-layout android-fragments ads android-orientation|
this question asked Jun 2 '14 at 21:53 Chris 1
|
1 Answers
1
Try this:
推荐:Android 2.3 Rotation and Orientation
Service: 28 window: [ android.view.IWindowManager] 38 activity: [ android.app.IActivityManager] 46 SurfaceFlinger: [ android.ui.ISurfaceComposer] 1) I
On android manifest in the activity that you want
android:configChanges="orientation|screenSize|keyboardHidden" >
and in the main activity:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
}
}
Thats work for me
|
this answer answered Jun 2 '14 at 23:40 Kakaman593 29 5
|
推荐:How to set Android camera orientation properly
This solution will work forallversions of Android. You can use reflection in Java to make it work for all Android devices: Basically you should create
推荐:How to set Android camera orientation properly
This solution will work forallversions of Android. You can use reflection in Java to make it work for all Android devices: Basically you should create
相关阅读排行
- 1Android Https相关完全解析 当OkHttp遇到Https
- 2Android APK反编译详解(附图)
- 3[置顶] Android APK反编译就这么简单 详解(附图)
- 4Android Fragment 真正的完全解析(上)
- 5Android RecyclerView 使用完全解析 体验艺术般的控件