ActivityManager:getLauncherLargeIconSize ()
1.作用
用于获取Lancher启动器的图标大小,返回值是int类型尺寸。
2.源码
public int getLauncherLargeIconSize() {
return getLauncherLargeIconSizeInner(mContext);
}
static int getLauncherLargeIconSizeInner(Context context) {
final Resources res = context.getResources();
final int size = res.getDimensionPixelSize(android.R.dimen.app_icon_size);
final int sw = res.getConfiguration().smallestScreenWidthDp;
if (sw < 600) {
return size;
}
final int density = res.getDisplayMetrics().densityDpi;
switch (density) {
case DisplayMetrics.DENSITY_LOW:
return (size * DisplayMetrics.DENSITY_MEDIUM) / DisplayMetrics.DENSITY_LOW;
case DisplayMetrics.DENSITY_MEDIUM:
return (size * DisplayMetrics.DENSITY_HIGH) / DisplayMetrics.DENSITY_MEDIUM;
case DisplayMetrics.DENSITY_TV:
return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH;
case DisplayMetrics.DENSITY_HIGH:
return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH;
case DisplayMetrics.DENSITY_XHIGH:
return (size * DisplayMetrics.DENSITY_XXHIGH) / DisplayMetrics.DENSITY_XHIGH;
case DisplayMetrics.DENSITY_XXHIGH:
return (size * DisplayMetrics.DENSITY_XHIGH*2) / DisplayMetrics.DENSITY_XXHIGH;
default:
return (int)((size*1.5f) + .5f);
}
}
3.分析及说明
DislayMetrics是一个用于描述结构化信息的展示,例如如大小、密度和字体缩放等等;
DisplayMetrics.DENSITY_LOW:低像素密度屏幕(像素密度:120)
DisplayMetrics.DENSITY_MEDIUM:中像素密度屏幕(像素密度:160)
DisplayMetrics.DENSITY_TV:电视像素密度屏幕(像素密度:213)
DisplayMetrics.DENSITY_HIGH:高像素密度屏幕(像素密度:240)
DisplayMetrics.DENSITY_XHIGH:X高像素密度屏幕(像素密度:280)
DisplayMetrics.DENSITY_XXHIGH:XX高像素密度屏幕(像素密度:320)