的测量单位请问Paint.setTextSize(浮点)使用? [英] Which unit of measurement does the Paint.setTextSize(float) use?

查看:216
本文介绍了的测量单位请问Paint.setTextSize(浮点)使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要使用画布 A视图中绘制具有特定的高度(像素)的文本。你可以简单地使用 Paint.setTextSize(浮点)与像素数或使用该 DP SP

I want to draw text with an specific height(in pixels) on a view using Canvas. Can you simply use Paint.setTextSize(float) with the number of pixels or is this using dp or sp?

推荐答案

它使用像素,但你可以把它转换使用此code到DP:

It uses pixels, but you can convert it to dp using this code:

double getDPFromPixels(double pixels) {
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    switch(metrics.densityDpi){
     case DisplayMetrics.DENSITY_LOW:
                pixels = pixels * 0.75;
                break;
     case DisplayMetrics.DENSITY_MEDIUM:
                 //pixels = pixels * 1;
                 break;
     case DisplayMetrics.DENSITY_HIGH:
                 pixels = pixels * 1.5;
                 break;
    }
    return pixels;
}

这篇关于的测量单位请问Paint.setTextSize(浮点)使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆