我注意到,當在android textview中使用setTextSize方法指定字體大小時,字體大小的小數是根據分辨率確定的,我通過使用getTextSize方法實現了這一點。Android中意外的字體大小在小數點的變化
我正在研究一個字體非常敏感的項目。在這個項目中,組件的定位和尺寸必須完全沒有變化。
例如,當我指定字體大小(如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不會對字體大小進行這樣的更改。
我不明白你自己改變字體大小的意思。你能給我一個可重現的代碼片段來證明這一點嗎? – Sweeper
我添加了示例代碼和圖像。 – seyfx