Density获取的部分在DisplayMetrics.java这个类里面,系统定义了3个等级的density,分别是low-120,medium-160,high-240。
代码中把Density设置为默认的Density,也就是当前,机器中的Density。那如何设置这个Density。同样在这个类最下面,找到系统获取Density的方法:
private static int
getDeviceDensity() {
// qemu.sf.lcd_density can be used to override ro.sf.lcd_density
// when running in the emulator, allowing for dynamic configurations.
// The reason for this is that ro.sf.lcd_density is write-once and is
// set by the init process when it parses build.prop before anything else.
return SystemProperties . getInt( " qemu.sf.lcd_density " ,
SystemProperties . getInt( " ro.sf.lcd_density " ,
// qemu.sf.lcd_density can be used to override ro.sf.lcd_density
// when running in the emulator, allowing for dynamic configurations.
// The reason for this is that ro.sf.lcd_density is write-once and is
// set by the init process when it parses build.prop before anything else.
return SystemProperties . getInt( " qemu.sf.lcd_density " ,
SystemProperties . getInt( " ro.sf.lcd_density " ,