2016-12-27 53 views
0

我正在创建一个需要风景/人像屏幕的应用程序。我的问题是,当屏幕旋转时,即使是记录器,该方法也不起作用,所以我很难在拍摄时遇到问题。任何有经验的人都一样吗?我在旋转后在日志中收到的是当屏幕旋转时,日志,方法不起作用风景

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"

+0

请在超级后在onConfigurationChanged内添加newConfig日志。并显示您的活动声明。 –

回答

0

通过默认的Android重新创建活动的旋转,所以你可以不用onConfigurationChanged都只是使用resource qualifiers。在你的情况下,只需将activity_task_page_lan.xml移动到res/layout-land /文件夹并重命名为activity_task_page.xml

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

+0

android:configChanges =“orientation | screenSize”我已经在我的清单中有这样的东西。是的,我自己处理它,因为我在横向模式下加载了一些额外的控件。 – jhaypee

+0

为什么您不希望只是在循环中重新创建活动并为onCreate中的其他控件编写条件逻辑? –