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是關鍵