public class ScreenUtils {
public static int getWidth(Context context) {
WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics outMetrics = new DisplayMetrics();
manager.getDefaultDisplay().getMetrics(outMetrics);
return outMetrics.widthPixels;
}
public static int getHeight(Context context) {
WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics outMetrics = new DisplayMetrics();
manager.getDefaultDisplay().getMetrics(outMetrics);
return outMetrics.heightPixels;
}
}
public class ConfigUtils {
public static boolean isOrientationPortrait(Context context) {
if (context.getResources().getConfiguration().orientation ==
Configuration.ORIENTATION_PORTRAIT) {
return true;
}
return false;
}
public static boolean isOrientationLandscape(Context context) {
if (context.getResources().getConfiguration().orientation ==
Configuration.ORIENTATION_LANDSCAPE) {
return true;
}
return false;
}
}
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者