デバイスがタブレットか電話かを判別するメソッドのメモ
private boolean isTabletDevice() { // Verifies if the Generalized Size of the device is XLARGE to be // considered a Tablet boolean xlarge = ((mContext.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == 4); // If XLarge, checks if the Generalized Density is at least MDPI // (160dpi) if (xlarge) { DisplayMetrics metrics = mContext.getResources().getDisplayMetrics(); // MDPI=160, DEFAULT=160, DENSITY_HIGH=240, DENSITY_MEDIUM=160, // DENSITY_TV=213, DENSITY_XHIGH=320 if (metrics.densityDpi == DisplayMetrics.DENSITY_DEFAULT || metrics.densityDpi == DisplayMetrics.DENSITY_HIGH || metrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM || metrics.densityDpi == 213/** DisplayMetircs.DENSITY_TV */ || metrics.densityDpi == 320/** DisplayMetrics.DENSITY_XHIGH */ ) { // Yes, this is a tablet! return true; } } // No, this is not a tablet! return false; }
大体これで大丈夫。
(これ前にも書いたっけ?)
0 件のコメント:
コメントを投稿