在drawable文件夹创建文件red_circle.xml (corners里面的数值要大于控件的高度)
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/doc_type_red" />
<corners
android:bottomLeftRadius="36dp"
android:bottomRightRadius="36dp"
android:topLeftRadius="36dp"
android:topRightRadius="36dp" />
</shape>
在布局文件中添加TextView (要设置高度与最小宽度,宽度要自适应)
<TextView
android:id="@+id/t_test"
android:layout_width="wrap_content"
android:layout_height="10dp"
android:background="@drawable/red_rounded_recatangle"
android:gravity="center"
android:minWidth="10dp"
android:text="123456"
android:textColor="@color/white"
android:textSize="10sp" />