Android:自动调整圆圈内文本的大小

Android:自动调整圆圈内文本的大小,android,Android,我有一个以圆圈为背景的文本视图。我想自动调整其中的数字大小,这样它就不会超出圆圈: 以下是我的文本视图: <TextView android:id="@+id/rank" android:layout_width="35dip" android:layout_height="35dip" android:layout_marginLeft="30dip"

我有一个以圆圈为背景的文本视图。我想自动调整其中的数字大小,这样它就不会超出圆圈: 以下是我的文本视图:

        <TextView
            android:id="@+id/rank"
            android:layout_width="35dip"
            android:layout_height="35dip"
            android:layout_marginLeft="30dip"
            android:layout_marginBottom="10dip"
            android:layout_marginTop="10dip"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:background="@drawable/circle_background"
            android:gravity="center"
            android:text="12345"
            android:maxLines="1"
            android:textColor="@color/white"
            android:textSize="15sp" />

以下是my circle_background.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
    <corners android:radius="10dip"/>
    <stroke android:color="#F5F5F5" android:width="5dip"/>
    <solid android:color="#F5F5F5"/>
</shape>


如何使其工作?

您可以使用新的appcompat功能。但它是预览功能,您需要升级依赖项


重要部分是:

android:autoSizeTextType=“统一” android:autoSizeMinTextSize=“12sp” android:AutoSizeMaxtSize=“100sp” android:autoSizeStepGranularity=“2sp”

有完整的迁移指南,您可以在需要时迁移到新的Andorid Studio

如果不需要,只需添加到顶级
build.gradle

maven{
url'https://maven.google.com'
}
然后将
build.gradle
中的依赖项从
25.4.0
替换为
26.0.0-beta2
中的应用程序兼容

还有另一个关于如何使用支持库的指南:

您仍将在以下方面使用您的部分:

android:background=“@drawable/circle\u background”
android:gravity=“center”

也许您需要为
TextView

设置一点填充,请用a)如何使用此功能b)如何获取26.0.0-beta2支持库扩展您的答案。基本上,你的答案需要足够好,以防我无法访问源代码。