简体   繁体   English

根据dpi和分辨率缩放TextView大小

[英]Scale TextView size according to dpi and resolution

How can I choose text size so that it looks the same on every device? 如何选择文本大小,以使其在每个设备上看起来都一样? I find it to be an impossible task, probably you will say that I should make different values for each dpi but that doesn't solve the problem, because there are phones with the same dpi but different screen resolution, and in the end it doesn't look the same. 我发现这是一项不可能完成的任务,可能您会说我应该为每个dpi设置不同的值,但这并不能解决问题,因为有些手机具有相同的dpi但屏幕分辨率不同,最后它并没有看起来不一样。 Anyone can help me here? 有人可以在这里帮助我吗?

The Android guidelines suggest to use the SP dimension for text: http://developer.android.com/training/multiscreen/screendensities.html Android准则建议对文本使用SP维度: http : //developer.android.com/training/multiscreen/screendensities.html

An SP dimension is dependent on the screen density but also user preferences. SP尺寸取决于屏幕密度,还取决于用户首选项。 Let's say a user configures his phone for big font (vision problems for example) your app will be accessible for this user. 假设某个用户将其手机配置为大字体(例如,视觉问题),则该用户可以访问您的应用。

In practice it looks like this: textSize="16sp" 实际上,它看起来像这样: textSize="16sp"

If you insist on having the same looks on every device, you can manage some details on different devices. 如果您坚持在每台设备上使用相同的外观,则可以管理不同设备上的一些详细信息。 Look at webpage Display class and WindowManager . 看网页Display类WindowManager Here is a sample code that I have used for a certain UI element: 这是我用于某个UI元素的示例代码:

Display display = getActivity().getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);

Good luck with this. 祝你好运。 It's not easy to manage all your graphics. 管理所有图形并不容易。

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

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