以编程方式设置textSize [英] Setting textSize programmatically
本文介绍了以编程方式设置textSize的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.result_font));
以下代码可以工作,但是R.dimen.result_font
的取值要比实际值大得多.根据屏幕大小,它可能约为18sp-22sp或24sp.但是这里设置的大小至少约为50sp.有人可以推荐一些东西吗?
The following code works, but the R.dimen.result_font
is taken as a much bigger value than it really is. Its maybe about 18sp-22sp or 24sp according to the screen size ... But the size set here is at least about 50sp. Can someone please recommend something ?
推荐答案
您必须将其更改为TypedValue.COMPLEX_UNIT_PX
,因为getDimension(id)
从资源中返回维度值,并且隐式转换为 px .
You have to change it to TypedValue.COMPLEX_UNIT_PX
because getDimension(id)
returns a dimen value from resources and implicitly converted to px.
Java:
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX,
getResources().getDimension(R.dimen.result_font));
科特琳:
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX,
resources.getDimension(R.dimen.result_font))
这篇关于以编程方式设置textSize的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文