简体   繁体   English

Android 围绕文本画圈

[英]Android draw circle around Text

I have a textView with a single character in it (all single digit, numbers 0-9).我有一个 textView,里面只有一个字符(都是单个数字,数字 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?我怎样才能在数字周围有一个圆圈?

Thanks谢谢

Just need to create a round drawable like this只需要像这样创建一个圆形可绘制对象

<?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.并将此可绘制对象设置为您的 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>

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM