Android examples for User Interface:Screen Size
Check if device screen screen size large.
//package com.java2s; import android.content.Context; import android.content.res.Configuration; public class Main { public static final String SCR_SIZE_SMALL = "small", SCR_SIZE_NORMAL = "normal", SCR_SIZE_LARGE = "large", SCR_SIZE_XLARGE = "xlarge"; /**/* ww w . jav a 2s . c om*/ * Check if device screen screen size large. * @param context The activity context or application context. * @return true if screen size is large, false if not. */ public static boolean isScrSizeLarge(Context context) { return getSizeName(context).equals("large"); } /** * Get the device size name. * @return String value of device size name(small, normal, large, xlarge). */ public static String getSizeName(Context context) { int screenLayout = context.getResources().getConfiguration().screenLayout; screenLayout &= Configuration.SCREENLAYOUT_SIZE_MASK; switch (screenLayout) { case Configuration.SCREENLAYOUT_SIZE_SMALL: return SCR_SIZE_SMALL; case Configuration.SCREENLAYOUT_SIZE_NORMAL: return SCR_SIZE_NORMAL; case Configuration.SCREENLAYOUT_SIZE_LARGE: return SCR_SIZE_LARGE; case 4: // Configuration.SCREENLAYOUT_SIZE_XLARGE is API >= 9 return SCR_SIZE_XLARGE; default: return "undefined"; } } }