Android中TextPaint setTextSize的单位是多少?

Gle*_*ech 3 android

开发.docs没有说明该单位.像素,dps,cm? http://developer.android.com/reference/android/graphics/Paint.html#setTextSize(float)

从实验来看,最可能的答案是像素,但我不确定.

Nik*_*ski 8

它是像素,因为setText()是本机方法,并且在Paint.h本机调用中将float转换为标量值,然后绘制它.当然,您可以通过以下方式申请dip以支持各种屏幕:

 float textSize =  TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, getResources().getDimension(R.dimen.text_size), getResources().getDisplayMetrics());
Run Code Online (Sandbox Code Playgroud)