Android 在文本周围绘制圆圈

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10060470/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 02:20:50  来源:igfitidea点击:

Android draw circle around Text

androidtextview

提问by user1154920

I have a textView with a single character in it (all single digit, numbers 0-9). I'd like to draw a circle or a square around the number. I saw a thread mention using a nine-patch to style around it, but I'm unsure of how to do this (or if it is the best way to do it). How can I have a circle around the number?

我有一个带有单个字符的 textView(所有单个数字,数字 0-9)。我想在数字周围画一个圆圈或一个正方形。我看到一个线程提到使用九个补丁来围绕它进行设计,但我不确定如何做到这一点(或者这是否是最好的方法)。我怎样才能在数字周围画一个圆圈?

Thanks

谢谢

回答by anticafe

Just need to create a round drawable like this

只需要像这样创建一个圆形的drawable

<?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>

And set this drawable as your TextView background.

并将此 drawable 设置为您的 TextView 背景。

回答by flagoworld

You should be able to just give that TextView a Shape drawable that is a circle as a background.

你应该能够给 TextView 一个 Shape drawable,它是一个圆形作为背景。

http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape

http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape