如何为 Paint.setTextSize() 设置单位 [英] How to set unit for Paint.setTextSize()
本文介绍了如何为 Paint.setTextSize() 设置单位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以更改Paint.setTextSize()
的单位?据我所知,它是像素,但我喜欢在 DIP 中设置文本大小以支持多屏幕.
Is it possible to change the unit for Paint.setTextSize()
? As far as I know, it's pixel but I like to set the text size in DIP for multiple screen support.
推荐答案
这样转换
// The gesture threshold expressed in dip
private static final float GESTURE_THRESHOLD_DIP = 16.0f;
// Convert the dips to pixels
final float scale = getContext().getResources().getDisplayMetrics().density;
mGestureThreshold = (int) (GESTURE_THRESHOLD_DIP * scale + 0.5f);
// Use mGestureThreshold as a distance in pixels
从这里 http://developer.android.com/guide/实践/screens_support.html#dips-pels
这篇关于如何为 Paint.setTextSize() 设置单位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文