我如何锁定屏幕方向的手机,而不是平板电脑? (安卓) [英] How do I lock screen orientation for phone, but not for tablet? (Android)

查看:575
本文介绍了我如何锁定屏幕方向的手机,而不是平板电脑? (安卓)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在一个Android项目,这是为了能够同时与Android手机和平板电脑兼容。在平板电脑上的应用程序是伟大的工作,看起来也不错。不过,在手机上,我们已经遇到了问题,以编程方式和布局明智的(采用了10.1英寸屏幕的工作是轻松了许多比4英寸的屏幕)。为了解决这些问题,我们决定关闭屏幕的方向,但只适用于手机的版本,ATLEAST是暂时的。

I have been working on a Android project, that is intended to be compatible with both the Android phones and tablets. On the tablet the app is working great and looks good too. However, on the phone we have been running into issues both programmatically and layout wise (working with a 10.1 inch screen is a lot easier than a 4 inch screen). To solve some of these problems we have decided to deactivate screen orientation but only for the phone version, atleast temporarily.

这个问题很简单,我怎么关闭屏幕方向的Andr​​oid手机,同时保持积极的Andr​​oid平板电脑?我知道我可以在manifest文件做到这一点,但是,这也将锁定方向的平板电脑,我相信。

The question is simple, how do I deactivate the screen orientation for Android phone, while keeping it active for the Android tablets? I know I can do this in the manifest file, however, this will also lock the orientation for the tablet I believe.

推荐答案

您可以从应用程序做得一样好。

You can do it from application as well.

锁定屏幕方向(安卓)
<一href="http://developer.android.com/reference/android/app/Activity.html#setRequestedOrientation%28int%29">http://developer.android.com/reference/android/app/Activity.html#setRequestedOrientation(int)

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

和属性都可以在这里找到:

And attributes can be found here:

<一个href="http://developer.android.com/reference/android/R.attr.html#screenOrientation">http://developer.android.com/reference/android/R.attr.html#screenOrientation

这篇关于我如何锁定屏幕方向的手机,而不是平板电脑? (安卓)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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