应用方向(横向或纵向)是怎么锁定? [英] How is application orientation (landscape or portrait) locked?

查看:621
本文介绍了应用方向(横向或纵向)是怎么锁定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用冻结方向:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

虽然显示停留在纵向,则活动仍重新创建。任何想法如何解决这个问题?

Although the display stays in portrait orientation, the activity is still recreated. Any ideas how to solve this?

如何应用的方向被锁定,使得该活动是不是在重新定位的变化?

How can the orientation of the application be locked such that the activity is not recreated on orientation change?

推荐答案

首先,请不要使用 setRequestedOrientation()如果你能避免它。使用机器人:screenOrientation在属性的<活性GT; 清单元素,而不是

First, don't use setRequestedOrientation() if you can avoid it. Use the android:screenOrientation attribute in your <activity> manifest element instead.

其次,你还需要安卓configChanges =keyboardHidden |定位&LT;活性GT; 清单元素prevent销毁/重新创建周期。

Second, you will also need android:configChanges="keyboardHidden|orientation" in your <activity> manifest element to prevent the destroy/recreate cycle.

这篇关于应用方向(横向或纵向)是怎么锁定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆