繁体   English   中英

Android 如何根据屏幕大小(而不是密度)减小文本大小

[英]Android how can I reduce the text size based on screen size (and NOT density)

我有一个简单的视图,上面有一些文本,我想做的就是想出一个为较小设备调整文本大小和填充的好方法,但我的问题是我不想考虑密度,只是屏幕尺寸本身。 这个想法是让应用程序在小型和大型设备之间看起来相同(包括填充等)

我看过很多关于使用限定符创建价值资源目录的帖子,但这并没有奏效,因为任何具有高 DP 的小型设备都会获得更大设备的填充和文本大小。

举个简单的例子,我希望文本大小在 Pixel 3 XL 上为 17sp,在 Nexus 5 上为 14sp,但似乎没有办法做到这一点,因为它们具有相似的像素密度,即使它们非常实际屏幕尺寸不同。 我错过了什么吗?

只有一种方法可以设置动态更改文本大小而不使用密度使用 android 默认字体大小,如下所示

style="@android:style/TextAppearance.DeviceDefault.Small"
style="@android:style/TextAppearance.DeviceDefault.Medium"
style="@android:style/TextAppearance.DeviceDefault.Large" 


<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    style="@android:style/TextAppearance.DeviceDefault.SearchResult.Title"
    android:text="Hello"/>

暂无
暂无

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

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