如何创建一个带有数字的圆形?

16

我正在使用AndEngine编写一个Android游戏。我想创建一个圆圈,里面有一个数字,就像这张图片中的一样:

2个回答

40

类似这样:

在 res/drawable 中的 circle.xml 文件。

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval" >

    <solid android:color="#aaf" />

</shape>

还有 circletext.xml(在 res/layout 中):

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:orientation="vertical" >

    <TextView
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_gravity="center"
        android:background="@drawable/circle"
        android:gravity="center"
        android:shadowColor="@android:color/white"
        android:shadowRadius="10.0"
        android:text="4"
        android:textColor="@android:color/black"
        android:textSize="18sp" />

</FrameLayout>

看起来是这样的:

在此输入图片描述


我在 TextView 中添加了以下属性,以便为更大的数字添加更好的修饰。 android:layout_width="wrap_content" android:layout_height="wrap_content" android:minHeight="14dp" android:minWidth="14dp" android:maxHeight="14dp" - elprl

1

我想最简单的方法就是放一个这样的图片哈哈。你可以使用一个带圆圈的图像,然后在其上方叠加数字文本。


我会创建很多东西,所以不能使用图片以获得更好的性能。 - Kadir
你可以使用一个简单的游戏引擎来处理图像。如果它们不动,它们就不应该占用太多处理器资源。即使是在移动时,大多数引擎也可以处理20或30个移动精灵,即使对所有精灵都应用了碰撞系统也没有问题。 - WingDev
使用源自位图的纹理不会对性能产生更大的影响,与使用源自绘图的位图的纹理相同。实际上它们是一样的。因为在GL中显示圆形必须首先将其转换为位图。 - Plastic Sturgeon

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接