0
我希望我的应用始终在平板电脑上显示风景,但应在手机上旋转。有没有办法做到这一点(除了有两个不同的apks)?有没有办法强制不同设备的不同方向?
我希望我的应用始终在平板电脑上显示风景,但应在手机上旋转。有没有办法做到这一点(除了有两个不同的apks)?有没有办法强制不同设备的不同方向?
使用方法check whether the device is a tablet,然后force orientation如果它是真的。
// From https://stackoverflow.com/questions/5832368/tablet-or-phone-android
public boolean isTablet(Context context) {
boolean xlarge = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == 4);
boolean large = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE);
return (xlarge || large);
}
// ...
// Do this from any Activity you do not wish to rotate on tablets:
if (isTablet(this))
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
AFAIK有在预期这些指令不工作的设备,他们一直等待的意见进行设置,等等 – Frank 2013-02-13 07:09:21
“等待即将成立的意见”?我不确定你的意思。只要你在'setContentView()'之前这样做了,它就没有等待的视图。 – Eric 2013-02-13 14:36:37