在App Development中缩放字体大小的理想方法是什么? [英] What is the ideal way to scale font size in App Development?

查看:31
本文介绍了在App Development中缩放字体大小的理想方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题听起来有点奇怪.我是Flutter开发的新手.在使我的应用程序响应时,我在缩放文本时总是遇到问题.如果我将字体大小保持不变(例如10或20),则有时在高分辨率的设备上看起来太小,或者在小型电话上看起来太大.然后我尝试相对于屏幕尺寸(例如4%或屏幕宽度等)缩放它,但是问题仍然在于相对于屏幕高度或宽度缩放它?因此,我想知道总体上缩放文本的理想方法是什么.

I know this question might sound a bit odd. I am a newbie in Flutter Development. While making my app responsive I always face an issue while scaling the text. If I keep the font size constant (say 10 or 20) it sometimes looks too small on devices with large resolution or too big on small phones. Then I tried scaling it with respect to screen dimensions (like 4% or screen width etc) but then the question remains to scale it with respect to screen height or width ? Hence I want to know what is the ideal way for scaling the text in general.

预先感谢您的回答.

推荐答案

您可以创建尺寸文件,并将根据设备的dpi使用这些文件中定义的尺寸.您将必须创建:

You can create dimension files and the sizes defined in these files will be used according to the device's dpi. You will have to create:

  1. res/values-mdpi/dimens.xml
  2. res/values-hdpi/dimens.xml
  3. res/values-xhdpi/dimens.xml
  4. res/values-xxhdpi/dimens.xml
  5. res/values-xxxhdpi/dimens.xml

以下是您要用于不同屏幕尺寸的比率:3:4:6:8:12(m:h:xh:xxh:xxxh)

Following are the ratios you would want to use for different screen size: 3:4:6:8:12 (m:h:xh:xxh:xxxh)

假设您有一个设备(hdpi),您想要将文本大小设置为12sp.因此,您将文本大小设置为:

Let's say you have a device(hdpi), you want to set the text size to 12sp. So you will set text sizes as:

  1. mdpi-9sp
  2. hdpi-12sp
  3. xhdpi-18sp
  4. xxhdpi-24sp
  5. xxxhdpi-36sp

确保所有"dimens.xml"中的名称都应相同

Make sure the name should be same in all 'dimens.xml'

res/values-mdpi/dimens.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
   <dimen name="title">12sp</dimen>
   <dimen name="paragraph">9sp</dimen>
</resources>

res/values-hdpi/dimens.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
   <dimen name="title">16sp</dimen>
   <dimen name="paragraph">12sp</dimen>
</resources>

res/values-xhdpi/dimens.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
   <dimen name="title">24sp</dimen>
   <dimen name="paragraph">18sp</dimen>
</resources>

res/values-xxhdpi/dimens.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
   <dimen name="title">32sp</dimen>
   <dimen name="paragraph">24sp</dimen>
</resources>

res/values-xxxhdpi/dimens.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
   <dimen name="title">48sp</dimen>
   <dimen name="paragraph">36sp</dimen>
</resources>

这篇关于在App Development中缩放字体大小的理想方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆