简体   繁体   中英

Android Tablet Landscape and Portrait Modes

I want to extend my mobile app to Android Tablet as well. 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.

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"

在此处输入图片说明

Then in your activity OnCreate method

@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">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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