【Android】屏幕尺寸的表示

1. 单位

- px(pixel): 普通的像素点描述,位图中的一个颜色点(RGBA或者YUV)

- dip(device independent pixels): 设备独立像素。

- dp: 与dip一样。

- pt(point): 标准长度单位。1pt = 1.0 / 72 (in)。

- sp(scaled pixel): 用于字体显示。

- in(inch): 英寸

- mm(millimeter): 毫米

2. 屏幕密度

屏幕类型宽度(pixels)高度(pixels)尺寸(inches)屏幕密度
QVGA2403202.6 - 3.0low
WQVGA2404003.2 - 3.5low
FWQVGA2404323.5 - 3.8low
HVGA3204803.0 - 3.5medium
WVGA4808003.3 - 4.0high
FWVGA4808543.5 - 4.0high
WVGA4808004.8 - 5.5medium
FWVGA4808545.0 - 5.8medium

 

 

 

 

 

 

 

 

 

 

 

 

 

默认屏幕密度:low = 120; medium = 160; high = 240

3. 屏幕单位的换算

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

303    /**
304     * Converts an unpacked complex data value holding a dimension to its final floating
305     * point value. The two parameters <var>unit</var> and <var>value</var>
306     * are as in {@link #TYPE_DIMENSION}.
307     *
308     * @param unit The unit to convert from.
309     * @param value The value to apply the unit to.
310     * @param metrics Current display metrics to use in the conversion --
311     *                supplies display density and scaling information.
312     *
313     * @return The complex floating point value multiplied by the appropriate
314     * metrics depending on its unit.
315     */
316    public static float applyDimension(int unit, float value,
317                                       DisplayMetrics metrics)
318    {
319        switch (unit) {
320        case COMPLEX_UNIT_PX:
321            return value;
322        case COMPLEX_UNIT_DIP:
323            return value * metrics.density;
324        case COMPLEX_UNIT_SP:
325            return value * metrics.scaledDensity;
326        case COMPLEX_UNIT_PT:
327            return value * metrics.xdpi * (1.0f/72);
328        case COMPLEX_UNIT_IN:
329            return value * metrics.xdpi;
330        case COMPLEX_UNIT_MM:
331            return value * metrics.xdpi * (1.0f/25.4f);
332        }
333        return 0; 334 }

/frameworks/base/core/java/android/util/DisplayMetrics.java
public static final int DENSITY_LOW = 120;
public static final int DENSITY_MEDIUM = 160;
public static final int DENSITY_TV = 213;
public static final int DENSITY_HIGH = 240;
public static final int DENSITY_XHIGH = 320;
public static final int DENSITY_400 = 400;
public static final int DENSITY_XXHIGH = 480;
public static final int DENSITY_560 = 560;
public static final int DENSITY_XXXHIGH = 640;
public static final int DENSITY_DEFAULT = DENSITY_MEDIUM;
public static final float DENSITY_DEFAULT_SCALE = 1.0f / DENSITY_DEFAULT;

public static int DENSITY_DEVICE = getDeviceDensity();
density =  DENSITY_DEVICE / (float) DENSITY_DEFAULT;

px = dip * density = dip * DENSITY_DEVICE / DENSITY_DEFAULT.

 

转载于:https://www.cnblogs.com/haorenjie/p/4132233.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值