TextView動態獲取字體大小設置異常情況處理

xml佈局如下設置的px

        <TextView
            android:id="@+id/tv_label"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:gravity="center_vertical"
            android:paddingLeft="@dimen/PX_8"
            tools:text="@string/fe_quick_note"
            android:maxLines="1"
            android:textColor="@color/common_font_33"
            android:textSize="@dimen/PX_28" />

代碼中獲取到的值:
var mTopAppItemTextSize = tv_name.textSize
根據手機分辨率的不同mTopAppItemTextSize會不一樣

如果重新設置回原來的值

tv_name?.setTextSize(TypedValue.COMPLEX_UNIT_PX, (mTopAppItemTextSize).toFloat())

TypedValue.COMPLEX_UNIT_PX是關鍵

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章