android:screenorientation 不起作用,为什么“android:screenOrientation =”后面“`在android 4.1.2中没有效果?...

作为测试样本,有2个活动的应用程序:MainActivity在按钮单击时启动SecondActivity。

它在Android 4.0.4上工作正常,但在Android 4.1.2上遇到意想不到的行为。

系统设置中的AutoRotation关闭(或者是 – 无关紧要,后面的选项也被忽略)。

android:screenOrientation =“Landscape”设置为MainActivity,而android:screenOrientation =“behind”被设置为SecondActivity,这意味着SecondActivity必须以横向方向启动。

Android 4.0.4是正确的,但在Android 4.1.2上SecondActivity从纵向开始。

AndroidManifest.xml中:

android:minSdkVersion="8"

android:targetSdkVersion="16" />

android:allowBackup="true"

android:icon="@drawable/ic_launcher"

android:label="@string/app_name"

android:theme="@style/AppTheme" >

android:name="com.my.example.testbehindorientation.MainActivity"

android:label="@string/app_name"

android:screenOrientation="landscape" >

android:name="com.my.example.testbehindorientation.SecondActivity"

android:configChanges="screenSize|orientation"

android:label="@string/title_activity_second"

android:screenOrientation="behind" >

SecondActivity.java:

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_second);

logOrientation("onCreate");

}

@Override

protected void onDestroy() {

super.onDestroy();

logOrientation("onDestroy");

}

@Override

protected void onResume() {

super.onResume();

logOrientation("onResume");

}

private void logOrientation(String prefix) {

int requestedOrientation = this.getRequestedOrientation();

WindowManager lWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);

Configuration cfg = getResources().getConfiguration();

int lRotation = lWindowManager.getDefaultDisplay().getRotation();

int orientation = cfg.orientation;

Log.i(LOG_TAG, prefix + ", requestedOrientation is " + requestedOrientation + ", rotation is " + lRotation + ", orientation is " + orientation);

}

在AndroidManifest.xml中对于第二个活动的日志输出没有android:configChanges =“screenSize | orientation”行按钮后单击MainActivity:

onCreate, requestedOrientation is 3, rotation is 1, orientation is 2

onResume, requestedOrientation is 3, rotation is 1, orientation is 2

onDestroy, requestedOrientation is 3, rotation is 0, orientation is 1

onCreate, requestedOrientation is 3, rotation is 0, orientation is 1

onResume, requestedOrientation is 3, rotation is 0, orientation is 1

用AndroidManifest.xml中包含的android:configChanges =“screenSize | orientation”进行日志记录:

onCreate, requestedOrientation is 3, rotation is 1, orientation is 2

onResume, requestedOrientation is 3, rotation is 1, orientation is 2

没有活动现在休闲,但结果总是一样的 – SecondActivity从纵向开始开始! 🙁

也就是说,由于某种原因,SecondActivity在onResume之后转为纵向。

为什么?..

测试:

> Samsung Galaxy S3与Android 4.0.4(好的)

> Samsung Galaxy S3搭配Android 4.1。 (错误)

>具有Android 4.1.2的仿真器,具有纵向主屏幕方向(错误)

> Android 4.0.3模拟器(好的)

> Android 4.2模拟器(Bug)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值