源码:

/frameworks/base/core/java/android/util/DisplayMetrics.java

194    /**195     * The logical density of the display.  This is a scaling factor for the196     * Density Independent Pixel unit, where one DIP is one pixel on an197     * approximately 160 dpi screen (for example a 240x320, 1.5"x2" screen),198     * providing the baseline of the system's display. Thus on a 160dpi screen199     * this density value will be 1; on a 120 dpi screen it would be .75; etc.200     *201     * 

This value does not exactly follow the real screen size (as given by202 * {@link #xdpi} and {@link #ydpi}, but rather is used to scale the size of203 * the overall UI in steps based on gross changes in the display dpi. For204 * example, a 240x320 screen will have a density of 1 even if its width is205 * 1.8", 1.3", etc. However, if the screen resolution is increased to206 * 320x480 but the screen size remained 1.5"x2" then the density would be207 * increased (probably to 1.5).208 *209 * @see #DENSITY_DEFAULT210 */211 public float density;

默认:

299    public void setToDefaults() {300        widthPixels = 0;301        heightPixels = 0;302        density =  DENSITY_DEVICE / (float) DENSITY_DEFAULT;303        densityDpi =  DENSITY_DEVICE;304        scaledDensity = density;305        xdpi = DENSITY_DEVICE;306        ydpi = DENSITY_DEVICE;307        noncompatWidthPixels = widthPixels;308        noncompatHeightPixels = heightPixels;309        noncompatDensity = density;310        noncompatDensityDpi = densityDpi;311        noncompatScaledDensity = scaledDensity;312        noncompatXdpi = xdpi;313        noncompatYdpi = ydpi;314    }

注释:

默认情况:density =  DENSITY_DEVICE / (float) DENSITY_DEFAULT;

DENSITY_DEVICE和DENSITY_DEFAULT在DisplayMetrics.java都有说明:

35    /**36     * Standard quantized DPI for medium-density screens.37     */38    public static final int DENSITY_MEDIUM = 160;...155    public static final int DENSITY_DEFAULT = DENSITY_MEDIUM;...162163    /**164     * The device's current density.165     * 

166 * This value reflects any changes made to the device density. To obtain167 * the device's stable density, use {@link #DENSITY_DEVICE_STABLE}.168 *169 * @hide This value should not be used.170 * @deprecated Use {@link #DENSITY_DEVICE_STABLE} to obtain the stable171 * device density or {@link #densityDpi} to obtain the current172 * density for a specific display.173 */174 @Deprecated175 public static int DENSITY_DEVICE = getDeviceDensity();...370 private static int getDeviceDensity() {371 // qemu.sf.lcd_density can be used to override ro.sf.lcd_density372 // when running in the emulator, allowing for dynamic configurations.373 // The reason for this is that ro.sf.lcd_density is write-once and is374 // set by the init process when it parses build.prop before anything else.375 return SystemProperties.getInt("qemu.sf.lcd_density",376 SystemProperties.getInt("ro.sf.lcd_density", DENSITY_DEFAULT));377 }

即:dpi为160时,density为1
 

更多相关文章

  1. 将ffmpeg编译到android 源码
  2. [置顶] Android学习进阶路线导航线路(Android源码分享)
  3. 在Ubuntu10.04上设置和下载android4.0源码
  4. MediaScannerReceiver
  5. 大虾们的 android 浅谈
  6. android几种开源项目源码地址
  7. android EditText 默认情况下不获取焦点(不弹出输入框)
  8. Android录音下————AudioRecord源码分析
  9. Android查看外部依赖jar的源码'Android(安卓)Private Libraries'

随机推荐

  1. [置顶] android popupwindow 弹出窗口在
  2. Android(安卓)studio APP开发第二章 Butt
  3. Android(安卓)9.0 AudioRecord代码分析
  4. android面试(7)-handler机制
  5. Android(安卓)View的绘制流程
  6. Android(安卓)UI 的几个简单技巧
  7. Android调试之TraceView
  8. 2011android面试题目及其答案大全
  9. 【Android每日一讲】2012.11.01 程序加载
  10. 为包含工作线程Android程序编写稳定的ins