【问题标题】:Logs , methods doesn't work when screen is rotate landscape日志,当屏幕旋转横向时方法不起作用
【发布时间】:2016-12-27 16:12:04
【问题描述】:

我正在创建一个需要横向/纵向屏幕的应用。我的问题是,当屏幕旋转时,即使是记录器,该方法也不起作用,所以我很难解决问题。有同样经历的人吗?轮换后我在日志中收到的是

12-28 00:02:55.897 13039-13039/com.xxx.xxx D/ViewRootImpl: ViewPostImeInputStage processPointer 0
12-28 00:02:55.927 13039-13039/com.xxx.xxx D/ViewRootImpl: ViewPostImeInputStage processPointer 1

在这里,我尝试在用户处于横向或纵向时加载不同的 XML。我使用这种方法是因为,在横向模式下我有额外的控件,而这些控件在纵向模式下不可用。所以我需要调用bindNewControlsLoaded() 方法来初始化这些控件。

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

        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
            setContentView(R.layout.activity_task_page_lan);
            initCreate();
            //im calling this because some controls are newly added
            bindNewControlsLoaded();
        } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
            setContentView(R.layout.activity_task_page);
            initCreate();
        }

    }

initCreate 方法是一个纵向的方法,用于加载常用控件。而在bindNewControlsLoaded(); 中调用了其他控件

在我的清单android:configChanges="orientation|screenSize"

【问题讨论】:

  • 请在 super 之后在 onConfigurationChanged 中添加带有 newConfig 的日志。并出示您的活动声明。

标签: android landscape-portrait


【解决方案1】:

默认情况下,android 在旋转时重新创建活动,因此您可以在没有 onConfigurationChanged 的情况下完成它,只需使用 resource qualifiers 。在您的情况下,只需将 activity_task_page_lan.xml 移动到 res/layout-land/ 文件夹并重命名为 activity_task_page.xml

但如果你真的想用你的代码来处理这种情况并阻止活动重新创建,你应该在活动声明中添加android:configChanges="orientation"

【讨论】:

  • android:configChanges="orientation|screenSize" 我的清单中已经有类似的东西了。是的,我自己处理它,因为我在横向模式下加载了一些额外的控件。
  • 为什么您不想只重新创建旋转活动并为 onCreate 中的其他控件编写条件逻辑?
猜你喜欢
  • 2018-08-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多