In dimens.xml, I have:
<dimen name="text_medium">18sp</dimen>
In runtime, I get this value and set the text size of a text view:
int size = context.getResources().getDimensionPixelSize(R.dimen.text_medium);
textView.setTextSize(size).
On a 10″ tablet (1280 x 800), everything is ok; but on a phone (800 x 480), the text view has a very large font. On the tablet, the size equals 18; on the phone, it's 27.
If I set the size manually by:
textView.setTextSize(size)
the size is normal on both devices.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…