改变机器人:动态configChanges [英] Changing android:configChanges dynamically

查看:143
本文介绍了改变机器人:动态configChanges的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建它使用一本杂志的应用程序在 ViewPager 并滚动,在不同的的WebView 秒。
大部分的网页是肖像但其中一些可以被看作是风景。

I am creating a magazine app which uses a ViewPager and scrolls over different WebViews. Most of the pages are portrait but some of them can be seen as landscape.

要解决这个问题,我使用了活动持有两种方法 ViewPager

To handle this, I am using two methods in the Activity holding the ViewPager:

public void allowOrientationChanges() {
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
}

public void enforcePortrait() {
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

通过这一点,我们确保刚需画像留肖像的所有页面(调用 getActivity()。enforcePortrait()),并有照片的那种/山水美景贯穿整个重启过程(调用 getActivity()。allowOrientationChanges())。

With this we make sure that all the pages that just need to be portrait stay portrait (calling getActivity().enforcePortrait()) and the ones that have portrait/landscape views goes through the whole restart process (calling getActivity().allowOrientationChanges()).

我们达到我们想要的视频添加到一些杂志的页面点。不幸的是HTML5视频标签不精细工作,所以我们增加了一个 VideoView 我们的布局。
现在添加的特点是:

We reached a point where we want to add video to some of the magazine's pages. Unfortunately the HTML5 video tag isn't working fine so we added a VideoView to our layout. The feature to add now is:


  • 在纵向:显示在某个地方的视频。 (完成!

  • 在景观:制作视频全屏播放(如YouTube应用)

我一直在努力做到这一点,我发现的唯一方法是改变 VideoView onConfigurationChanged()活动方式并通知片段的配置改变。这样做的问题是添加的android:configChanges =方向| keyboardHidden活动将禁止的意见重新创建。

I have been trying to do this and the only way I found is changing the size of the VideoView in the onConfigurationChanged() method in the Activity and notifying the fragment that the configuration changed. The problem with this is adding android:configChanges="orientation|keyboardHidden" to the Activity will "disallow" the views to be recreated.

这两个可能的解决方案我认为是:

The two possible solutions I thought of:


  1. 更改的android:configChanges 从code,并根据网页上,但如果该呼叫存在我找不到

  2. onConfigurationChanged()方法强制重新创建。我不知道如何强制片段
  3. 的娱乐
  1. Changing the android:configChanges from the code and depending on the page but I couldn't find if that call exists.
  2. Forcing a recreate on the onConfigurationChanged() method. I don't know how to force a recreation of the fragment.

任何想法?

推荐答案

我只是固定它。谢谢您的回答。

I just fixed it. Thanks for your answers.

我的解决办法是让活动的android:configChanges =方向| keyboardHidden标志

My solution was to make the Activity have the android:configChanges="orientation|keyboardHidden" flag.

这样做,我重写片段其中,我调整<$ C $在 onConfigurationChanged()方法后C>的WebView VideoView 根据我的需要。

After doing that I override the onConfigurationChanged() method inside the Fragment where I resize the WebView or the VideoView depending on what I need.

编辑:

我只是做了博客文章这个问题。

这篇关于改变机器人:动态configChanges的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆