简体   繁体   English

Android Tablet横向和纵向模式

[英]Android Tablet Landscape and Portrait Modes

I want to extend my mobile app to Android Tablet as well. 我也想将移动应用程序扩展到Android Tablet。 My mobile app supports only Portrait mode in mobile but in Tablet I want to support both Landscape and Portrait modes. 我的移动应用程序在移动设备中仅支持纵向模式,但是在平板电脑中,我想同时支持横向和纵向模式。

But I don't want to change modes at runtime. 但是我不想在运行时更改模式。

For Ex. 对于前 If the user opens the app with his Tablet in Landscape mode, the app should run only in Landscape mode even if he rotates to Portrait while using the app. 如果用户使用其平板电脑在横向模式下打开该应用程序,则即使他在使用该应用程序时旋转为纵向,该应用程序也应仅在横向模式下运行。

This is possible in iPad but I don't know if it is possible in Android Tablet. iPad可以做到这一点,但我不知道Android平板电脑是否可以做到。

If it is possible how do I do it? 如果可能的话我该怎么办?

Is not a orthodox way, but you can achieve it like this, create 2 resource files one generic and one for sw600dp (tablet) and add a bool "istablet" 这不是一种正统的方法,但是您可以这样实现,创建2个资源文件(一个通用文件,一个用于sw600dp(平板电脑)),然后添加bool“ istablet”

在此处输入图片说明

Then in your activity OnCreate method 然后在您的活动中OnCreate方法

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if(!getResources().getBoolean(R.bool.is_tablet)) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
    }

you can provide default orientation in manifest file like this 您可以像这样在清单文件中提供默认方向

 <activity
        android:name=".MainActivity"
        android:screenOrientation="portrait">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM