是否可以更改Paint.setTextSize()
的单位?据我所知,它是像素,但我想在DIP中设置文本大小以支持多屏幕。
最佳答案
像这样转换
// 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/practices/screens_support.html#dips-pels