【发布时间】: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