Android屏幕密度与UI大小显示

在Android开发中,屏幕密度的变化可能导致UI显示大小问题。通过调整ro.sf.lcd_density属性,可以解决不同屏幕分辨率下UI尺寸的问题。DisplayMetrics.java中获取此属性,density值分别对应ldpi、mdpi、hdpi等资源目录。使用dip和sp单位能实现设备独立像素和字体大小的适配,适应不同屏幕密度。
摘要由CSDN通过智能技术生成

在调试产品的时候经常会遇到因为LCD屏分辨率不一样而导致UI显示过大或过小的情况,修改了属性系统中的变量ro.sf.lcd_density(device_base.mk),根据对应的屏幕增大或减小对应的值,问题一般都能解决。

在frameworks/base/core/java/android/util/DisplayMetrics.java文件中会去获取这个属性的值

public static final int DENSITY_DEVICE = getDeviceDensity();


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));
    }


density表示显示密度,表示每英寸有多少个显示点,但是这个显示点与

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值