【发布时间】:2021-03-06 07:14:19
【问题描述】:
我有一个 textView,其中包含一个字符(所有单个数字,数字 0-9)。我想在数字周围画一个圆圈或一个正方形。我看到一个线程提到使用九个补丁来围绕它进行样式设置,但我不确定如何做到这一点(或者它是否是最好的方法)。我怎样才能在数字周围有一个圆圈?
谢谢
【问题讨论】:
我有一个 textView,其中包含一个字符(所有单个数字,数字 0-9)。我想在数字周围画一个圆圈或一个正方形。我看到一个线程提到使用九个补丁来围绕它进行样式设置,但我不确定如何做到这一点(或者它是否是最好的方法)。我怎样才能在数字周围有一个圆圈?
谢谢
【问题讨论】:
只需要像这样创建一个圆形可绘制对象
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<corners android:radius="10dip"/>
<stroke android:color="@color/red" android:width="2dip"/>
<solid android:color="@android:color/transparent"/>
</shape>
并将这个drawable设置为你的TextView背景。
【讨论】:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke android:color="@color/teal_200" android:width="2dip"/>
<solid android:color="@android:color/transparent"/>
<size
android:width="10dp"
android:height="10dp"
/>
</shape>
【讨论】:
您应该能够只给 TextView 一个 Shape drawable,它是一个圆形作为背景。
http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape
【讨论】: