码迷,mamicode.com
首页 > 移动开发 > 详细

设置安卓设备屏幕方向,平板为横屏,手机为竖屏

时间:2014-08-08 17:43:16      阅读:779      评论:0      收藏:0      [点我收藏+]

标签:android   http   io   for   ar   cti   html   new   

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.

设置安卓设备屏幕方向,平板为横屏,手机为竖屏,布布扣,bubuko.com

设置安卓设备屏幕方向,平板为横屏,手机为竖屏

标签:android   http   io   for   ar   cti   html   new   

原文地址:http://www.cnblogs.com/zwliuxing/p/3899674.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!