16

I'm programming an Android game using AndEngine. I want to create a circle which has a number in, like in this picture:

Philipp Reichart
  • 20,771
  • 6
  • 58
  • 65
Kadir
  • 411
  • 1
  • 6
  • 19

2 Answers2

40

Something like this:

circle.xml (in res/drawable)

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

and circletext.xml (in 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>

looks like this:

enter image description here

Alec B. Plumb
  • 2,490
  • 25
  • 25
  • I added the following properties to TextView to add better polish for bigger numbers. android:layout_width="wrap_content" android:layout_height="wrap_content" android:minHeight="14dp" android:minWidth="14dp" android:maxHeight="14dp" – elprl Oct 10 '15 at 17:48
1

Well I guess the simplest way is to just put a picture like that in haha. You could always use an image with a circle then layer the text with the number over the top of it.

WingDev
  • 137
  • 5
  • i will create a lot.so i can't use images for good performance. – Kadir Apr 10 '12 at 21:47
  • You could use a simple game engine to handle the images. They shouldnt be processor intensive then if they arent moving. Even then, most engines can handle 20 or 30 moving sprites without a problem, even with a collision system applied to all of them. – WingDev Apr 10 '12 at 22:01
  • using an texture whose source is a bitmap will not impact your performance any more than using a texure who's source is an bitmap drawn from paint. In fact they will be the same. Because in order to display the circle in GL it must be a bitmap first. – Plastic Sturgeon Apr 16 '12 at 23:15