2017-07-17 85 views
0

我注意到,当在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 DP40.2 DP

https://i.stack.imgur.com/A4s2c.png

之间没有变化有没有什么办法来防止呢?

注意:IOS不会对字体大小进行这样的更改。

+0

我不明白你自己改变字体大小的意思。你能给我一个可重现的代码片段来证明这一点吗? – Sweeper

+0

我添加了示例代码和图像。 – seyfx

回答

1

尝试在dp中设置文字大小。如果您在sp中设置文本大小,则可能会发生更改。阅读文档Link

+0

我更新了问题。没有变化。 – seyfx