【发布时间】:2012-09-26 14:24:27
【问题描述】:
我正在开发一个只支持两种方向的应用程序,纵向和反向纵向,所以我在清单中写了“sensorPortrait”,它运行良好。
问题是,我想为这两个方向使用不同的布局。
启用sensorPortrait 会禁用“onConfigurationChange”调用。
我用:
orientationEventListener = new OrientationEventListener(this) {
@Override
public void onOrientationChanged(int i) {
int newOrientation = getScreenOrientation();
if (newOrientation != orientation) {
orientation = newOrientation;
if (newOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
...
setContentView(R.layout.main);
} else if (newOrientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT) {
...
setContentView(R.layout.main_reverse_portrait);
}
}
}
};
orientationEventListener.enable();
问题是在更改方向后调用此代码,因此当用户首先旋转手机时,他们会看到之前的布局,Android 自动旋转,然后是正确的布局。看起来无法接受,您知道如何解决吗?
【问题讨论】:
标签: android android-layout android-orientation