为什么android在使用小于12sp的尺寸时会发出警告?

hfsqlsce  于 2023-05-05  发布在  Android
关注(0)|答案(3)|浏览(319)

我正在为7英寸平板电脑开发应用程序,更特别的是为nexus7开发,在XML布局文件中,我得到了警告

避免使用小于12sp的大小:11sp

如果我设置任何文本字段的大小小于12sp?
我正在添加屏幕截图,以便更清楚地了解问题

xwbd5t1u

xwbd5t1u1#

对于默认字体缩放,1 sp = 1dip = 1/160”。11 sp的高度大约是1/15英寸,相当微小。
这是一个Lint错误。您可以覆盖它--按<Ctrl>-<1>,快速修复列表菜单应该给予显示该消息。
但是,如果你尝试12 sp,你可能会看到它也是非常小的,你想要一个更大的字体无论如何。

vjrehmav

vjrehmav2#

您可以使用**tools:ignore="SmallSp"**忽略该警告

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:singleLine="false"
    android:text="NileshRathod"
    android:textSize="8sp"
    tools:ignore="SmallSp"/>
daolsyd0

daolsyd03#

我使用Android Studio Flamingo | 2022.2.1 Patch 1
避免使用小于11sp的大小。
您应该添加到tools:ignore="SmallSp"

<TextView
        android:textSize="10sp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:ignore="SmallSp" />

相关问题