Android的:如何坚持同一方向的活动开始 [英] Android: How to stick to the same orientation the Activity started with
本文介绍了Android的:如何坚持同一方向的活动开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道如何锁定特定方向的活动(在的AndroidManifest.xml 的):
安卓screenOrientation =山水|人像
我知道如何锁定到一个特定的方向编程方式:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
不过,我怎么锁定活动中,在开始的方向?例如,如果它开始画像,应该坚持到底。 P>
谢谢!
解决方案
找到了解决方法:
开关(((窗口管理器)getSystemService(WINDOW_SERVICE))。getDefaultDisplay()。getRotation()){
案例Surface.ROTATION_90:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
打破;
案例Surface.ROTATION_180:
setRequestedOrientation(9 / * reversePortait * /);
打破;
案例Surface.ROTATION_270:
setRequestedOrientation(8 / * reverseLandscape * /);
打破;
默认 :
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
发现这里。
I know how to lock an activity in a specific orientation (in AndroidManifest.xml):
android:screenOrientation="landscape|portrait"
I know how to lock to a specific orientation programmatically:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
But, how do I lock the activity to the orientation in which started at? e.g., if it started portrait, it should stick to that.
Thanks!
解决方案
Found a solution:
switch (((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay().getRotation()) {
case Surface.ROTATION_90:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
break;
case Surface.ROTATION_180:
setRequestedOrientation(9/* reversePortait */);
break;
case Surface.ROTATION_270:
setRequestedOrientation(8/* reverseLandscape */);
break;
default :
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
Found it here.
这篇关于Android的:如何坚持同一方向的活动开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文