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 " , DENSITY_DEFAULT));
}
// 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 " , DENSITY_DEFAULT));
}
而如何给系统设置Density,就在./device/eshion/f101/init.rc,添加setprop ro.sf.lcd_density 240.
更改系统像素是在./framework/core/java/android/content/res/CompatibilityInfo.java下:
public static final int DEFAULT_PORTRAIT_WIDTH = 600;宽像素
public static final int DEFAULT_PORTRAIT_HEIGHT= 1024;长像素