从系统设置更改字体大小时,Android TextView(大小设置为sp)不会更改大小

时间:2020-03-13 11:06:23

标签: android android-layout textview android-textview-autosize

android:textSize设置为16sp,即使系统字体大小增加到最大时,字体大小也是固定的。

 android:layout_width="match_parent"
 android:layout_height="wrap_content"

TextView包含在FrameLayout中

2 个答案:

答案 0 :(得分:1)

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="8dp"
    android:paddingTop="8dp"
    android:paddingRight="8dp"
    android:paddingBottom="8dp">

    <TextView
        android:id="@+id/item_barcode_codice_fiscale_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Font Size"
        android:textSize="80sp"/>
</FrameLayout>

在我这边工作。试试吧。
重建或清理项目。谢谢 提前。 enter image description here

答案 1 :(得分:0)

如果您不希望字体大小根据系统字体大小而改变,建议您在dp中使用大小。

如您在Decouments中看到的那样:

sp是相同的基本单位,但是会根据用户的首选文本大小进行缩放(这是与缩放无关的像素),因此在定义文本大小时(但绝不用于布局大小)应该使用此度量单位。