简体   繁体   English

字体大小基于dpi,android

[英]Font size based on dpi, android

This seems to be a basic question, but I am not able to figure it out. 这似乎是一个基本问题,但我无法弄清楚。 I am creating an app which will run on ldpi, mdpi, hdpi, xhdpi, xxhdpi. 我正在创建一个将在ldpi,mdpi,hdpi,xhdpi,xxhdpi上运行的应用程序。 I have a phone which is hdpi. 我有一部hdpi的电话。 Now font sizes are best judged when seen on a physical phone/tablet. 现在,在物理电话/平板电脑上查看时,最好判断字体大小。

So say If it looks good on 18 pixel font on hdpi, on what sizes would it look good on others. 可以这么说,如果在hdpi的18像素字体上看起来不错,那么在其他尺寸上看起来就不错。 Any ideas, best known good practices? 有什么想法,最知名的良好做法吗?

Thanks 谢谢

Maybe this will help. 也许这会有所帮助。 Try using setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); 尝试使用setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); in Java code 用Java代码

Try using sp as the unit of the fontsize. 尝试使用sp作为字体大小的单位。 an 18px font should be 9sp on an hdpi device, and the os automatically scales it based on the density. 在hdpi设备上,18px字体应为9sp,并且os会根据密度自动缩放。

尝试使用setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);

尝试这个

setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM