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);
}
}
您可以像这样在清单文件中提供默认方向
<activity
android:name=".MainActivity"
android:screenOrientation="portrait">
链接地址: http://www.djcxy.com/p/37964.html
上一篇: 什么是最适合模板的C ++代码覆盖工具?
下一篇: Android平板电脑风景和肖像模式