首页 > 代码库 > 设置安卓设备屏幕方向,平板为横屏,手机为竖屏
设置安卓设备屏幕方向,平板为横屏,手机为竖屏
http://stackoverflow.com/questions/9627774/android-allow-portrait-and-landscape-for-tablets-but-force-portrait-on-phone
Here‘s a good way using resources and size qualifiers.
Put this bool resource in res/values as bools.xml or whatever (file names don‘t matter here):
<?xml version="1.0" encoding="utf-8"?> <resources> <bool name="portrait_only">true</bool> </resources>
Put this one in res/values-sw600dp and res/values-xlarge:
<?xml version="1.0" encoding="utf-8"?> <resources> <bool name="portrait_only">false</bool> </resources>
Then, in the onCreate method of your Activities you can do this:
if(getResources().getBoolean(R.bool.portrait_only)){ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); }
Devices that are more than 600 dp in the smallest width direction, or x-large on pre-Android 3.2 devices (tablets, basically) will behave like normal, based on sensor and user-locked rotation, etc. Everything else (phones, pretty much) will be portrait only.
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。