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;
}
}
网友评论