【发布时间】:2017-12-21 23:06:34
【问题描述】:
我注意到当在android textview中使用setTextSize方法指定字体大小时,字体大小的小数是根据分辨率确定的,我通过使用getTextSize方法实现了这一点。
我正在处理一个字体敏感度非常高的项目。在这个项目中,组件的位置和大小必须绝对零变化。
例如,当我指定字体大小(例如 30.777777777)时,我不希望 Android 对其进行任何更改。
实际样本:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.test.magazinetest.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SAMPLE TEXT"
android:textSize="40dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SAMPLE TEXT"
android:textSize="40.2dp" />
</LinearLayout>
完全相同的结果:40 dp 和 40.2 dp
之间没有变化https://i.stack.imgur.com/A4s2c.png
有什么办法可以防止这种情况发生吗?
注意:IOS 不会对字体大小进行这样的更改。
【问题讨论】:
-
我不明白你所说的 android 自己改变字体大小的意思。你能给我一段可重现的代码来证明这一点吗?
-
我添加了示例代码和图片。
标签: android fonts size decimal