設置textView的字體大小和資源文件不一致的問題

今天想對程序裏的文字作個適配,網上找到了個你們瘋轉的方法。this.getResources().getDimension(); android

因而乎就引出了下面的問題,我不知道是什麼問題。也沒找到答案! 佈局

本着測試爲主,就創建了一個,如下是dimens.xml的代碼: 測試

<resources>
  <dimen name="text_size">24.0sp</dimen>
</resources>



如下是佈局文件的代碼:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center"
    android:background="@drawable/login_bg"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/test_text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="測試"
        android:textColor="#000000" />
    
    
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="測試"
        android:textColor="#000000"
        android:textSize="@dimen/text_size" />
    

</LinearLayout>



最後是打印出來的結果:

模擬器分是: this

我沒有找到關於解釋的資料~ 實在是是搞不懂。 code

我的初步懷疑,它把sp還原成了px~~ xml

不知道你們有沒有遇到過~ 有的話能夠聊聊~ utf-8

相關文章
相關標籤/搜索