android - 在圆圈内绘制文字

标签 android drawable

我正在开发一个 Android 应用程序,我想画一个圆圈,里面有文字。我希望填充为白色,黑色边框和黑色文本。现在我有一个 ShapeDrawable:

mDrawable = new ShapeDrawable(new OvalShape());
mDrawable.getPaint().setColor(0xFFFFFF);

然而,这会使整个圆圈变成白色(并且在白色背景下您看不到它)并且搜索了一段时间后如何向形状添加文本我似乎无法找到有效的答案。我还应该注意,我将根据用户输入在每个圆圈中添加任意数量的不同文本。任何帮助将非常感激!

最佳答案

您可以试试这个替代方法。

创建可绘制文件 oval.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
   <solid android:color="#fff"/>
   <stroke android:width="2px" android:color="#000"/>
</shape>

然后创建一个 RelativeLayout 并使用椭圆形 drawable 设置背景

<RelativeLayout
    android:id="@+id/circle"
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:layout_gravity="center"
    android:background="@drawable/oval" >

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="@string/hello_world" />
</RelativeLayout>

结果会是这样的:

enter image description here

关于android - 在圆圈内绘制文字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20168016/

相关文章:

java - Android fragment 错误 : No view found for id 0x7f08009e (com. example.myapplication:id/preferenceFragment) fragment

java - Android:Thread Runnable 和 Handler.post 问题 - 在 Run 方法中(Handler.postXX 没有按预期运行)

Android OntouchListener,绘制位图时检查图像相交

java - 如何以编程方式更改图像的不透明度并将其保存在图库中

android - 如何在 android 设备上获取应用程序崩溃详细信息(自己的统一应用程序)

android - UI 应该中断的最长时间是多少?

android - BroadcastReceiver 的返回值

android - 仅在实体右侧使用 Stroke 可绘制

带有扫弧的android可绘制圆圈

安卓|有意地给出图像