Android:如何按设备类型(平板电脑、手机)设置强制设备方向? [英] Android : How set force device orientation by device type (tablet, phone)?

查看:38
本文介绍了Android:如何按设备类型(平板电脑、手机)设置强制设备方向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要根据使用相关视图的设备类型(平板电脑的横向视图和移动设备的纵向视图)设置强制定向设备,无法在设备上更改旋转.

I need to set force orientation device based on the type of the device for using related view (landscape view for tablets and portrait for the mobile devices) rotation cannot be changed on device.

因为我想在应用程序启动期间为所有活动设置方向,我认为我应该识别主活动中的设备类型,该活动由与视图相关的其他活动扩展.

Because i would like to set orientation for all activities during the start of the app i thought that i should to recognize device type in the main activity which is extended by the other activities related with views.

请问我怎样才能以正确的方式做到这一点?

How can i do it in the right way please?

非常感谢您的建议.

推荐答案

在您的主要活动(启动器活动)或应用程序类中使用它,

Use this in your main activity(Launcher activity) or in Application class,

if (isTablet(mContext))
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
            else
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    public static boolean isTablet(Context context) {
            return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK)
                    >= Configuration.SCREENLAYOUT_SIZE_LARGE;
        }

这篇关于Android:如何按设备类型(平板电脑、手机)设置强制设备方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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