力平板电脑将在横向模式 [英] Force tablet to be in landscape mode

本文介绍了力平板电脑将在横向模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法强制平板电脑将在横向模式为默认的方向,当用户启动的我的应用程序。有没有办法与主题化或类似的东西做到这一点,所以用户doent看到的方向变化时,他启动的应用程序?

注:相同的应用程序是(应该是)在纵向模式下的手机

现在我有一个布尔值的文件夹refs.xml(包括价值观和价值观大)与平板电脑和手机不同的值,但用户可以看到该应用程序是旋转 code:

 公共静态布尔isTablet(上下文的背景下){
        返程(context.getResources()getBoolean(R.bool.isTablet));
    }
 

解决方案

 如果(isTablet(getApplicationContext())){
          setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    } 其他 {
          setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
    的setContentView(R.layout.yourlayout);



** //此方法用于检查片剂或没有运行?**

     公共静态布尔isTablet(上下文的背景下){
         返程(context.getResources()。getConfiguration()。屏幕布置
                        &放大器; Configuration.SCREENLAYOUT_SIZE_MASK)
                        > = Configuration.SCREENLAYOUT_SIZE_LARGE;
     }
 

Is there a way to force the tablet to be in landscape mode as default orientation when the user start's my app. Is there a way to do this with theming or something like that, so the user doent see orientation change when he is starting the app?

Note: the same app is (should be) in portrait mode for phones

For now I have a boolean values folder refs.xml(both values and values-large) with different value for tablet and phone, but the user can see that the app is rotating Code:

public static boolean isTablet(Context context) {   
        return (context.getResources().getBoolean(R.bool.isTablet));
    }

解决方案

    if (isTablet(getApplicationContext())) {
          setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    } else {
          setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
    setContentView(R.layout.yourlayout);



**//this method for check having run in tablet or not??**

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

这篇关于力平板电脑将在横向模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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