Android sp vs dp 文本 - 什么会调整“比例"以及支持的理念是什么 [英] Android sp vs dp texts - what would adjust the 'scale' and what is the philosophy of support

查看:10
本文介绍了Android sp vs dp 文本 - 什么会调整“比例"以及支持的理念是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我们从许多其他帖子中知道,我们应该在 Android 中使用 sp 而不是 dp 来处理文本,我们知道这样做的原因是为了尊重用户的偏好".

So we know from many other posts that we should use sp rather than dp for text in Android, and we know the reason for this is to respect a 'user's preferences'.

但这些偏好究竟是什么?用户如何更改此设置?

But precisely what are these preferences? How might a user change this setting?

我无法通过手机上的设置找到任何参考(我本来希望在辅助功能"或显示"中出现某些内容).那么什么是用户设置?是不是只能通过大字体"之类的应用来完成?

I cannot find any reference through the settings on my phone (I would have expected something in 'Accessibility' or 'Display'). So what is a user setting? Is it only done through the likes of an app such as 'Big Font'?

假设它是(由类似大字体的东西设置) - 我玩过 Google Docs 和其他一些 Google 应用程序,字体设置为 130%.虽然大多数布局都很好,但有些布局被截断并且无法读取(这是在大屏幕 SGS2 上).那么,使用sp"开发具有文本大小的应用程序的方法是什么?我们是否确保它适用于 100% 缩放,然后忽略其他设置 - 称其为用户可以担心的特殊情况,或者我们是否竭尽全力确保内容扩展或可滚动,以防文本溢出?

Assuming that it is (set by something like big font) - I have played with Google Docs and some other Google apps with the font set to 130%. While most layout stays fine, some gets a bit cut off and can't be read (and that is on a big screened SGS2). So, what is the approach to developing apps with text sizes using 'sp'? Do we make sure it works on 100% scaling and then ignore other settings - call it a special case that the user can worry about, or do we go out of our way to make sure things expand or are scrollable, in case the text overflows?

一个论点是我们应该使用dp"来保证用户有机会看到文本(即使他们必须使用放大镜)

One argument is that we should use 'dp' to guarantee a user has a chance of seeing the text (even if they have to use a magnifying glass)

想法/评论?

推荐答案

它在某些 Android 设备的设置菜单中公开(取决于制造商).它也可能被一些可访问性选项(取决于设备)改变.

It is exposed in the settings menu on some Android devices (manufacturer dependent). It may also be altered by some accessibility options (device-dependent).

通常,您应该始终使用与比例无关的像素,尤其是对于大量文本.

In general, you should always used scale-independent pixels, especially for a large body of text.

但是,如果您的文本必须适合已知大小的边界框,那么您应该使用与密度无关的像素,以确保文本始终正确适合,并且无论用户的设置如何,所有字符都是可见的.

However if your text has to fit into a bounding-box of known size then you should use density independent pixels in order to ensure that the text always fits properly and that all characters are visible regardless of the users' setting.

简而言之:将文本大小增加 5sp 左右会导致文本不可读或破坏您的 UI?如果是这样,请使用与密度无关的像素.如果不是,请使用与比例无关的像素.但是,您通常应该尽可能使用与比例无关的像素,这意味着设计一个可以适应不同文本大小的 UI.

In a nutshell: would increasing the text-size by around 5sp result in the text being unreadable or mangle your UI? If so use density-independent pixels. If not, use scale-independent pixels. However you should generally aim to use scale-independent pixels wherever possible, which means designing a UI that can accommodate different text sizes.

这篇关于Android sp vs dp 文本 - 什么会调整“比例"以及支持的理念是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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