Android App兼容平板的开发。希望在手机上是竖屏显示,然后在平板上是横竖切换。
/**
* 判断是否平板设备
* @param context
* @return true:平板,false:手机
*/
public static boolean isPad(Context context) {
return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}
if(UIHelper.isPad(appContext)){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
}else{
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
这里还要在xml配置文件上加上:android:configChanges,特别这个screenSize不能忘,兼容4.0以上版本,不然横竖屏切换会死掉。
<activity android:name=".ui.SfbMain" android:theme="@style/Theme.HalfTranslucent" android:configChanges="keyboardHidden|orientation|screenSize|screenSize" >