问题
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));
}
回答1:
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;
}
回答2:
Landscape does not mean this is tablet. You should put isTablet
for tables in XML file stored in res/values-sw600dp
instead.
回答3:
You should use android:screenOrientation="landscape"
in Manifest
file where you define your activities
<activity
android:name="com.yourpackage.ActivityClassName"
android:label="@string/app_name"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
回答4:
I think you just need to add screenOrientation
in your activity tag
in manifest.xml
as below :
<activity>
android:screenOrientation="landscape"
</activity>
And you application will open in landscape
mode
回答5:
add below line in your manifest under activity tag...
android:screenOrientation="landscape"
来源:https://stackoverflow.com/questions/25638611/force-tablet-to-be-in-landscape-mode