Android : Draw Circle With Text Inside

Try this

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/num_txt"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:layout_marginTop="0dp"
                android:background="@drawable/bg_red"
                android:gravity="center"
                android:text="My name is NON"
                android:textColor="#FFFFFF"
                android:textSize="10dp" />

        </RelativeLayout>

    </RelativeLayout>

Save in drawable bg_red.xml

    <?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="#FF0000" android:width="5dip"/>
        <solid android:color="#FF0000"/>
    </shape>

Edited Code

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="match_parent" >
         <TextView
             android:id="@+id/num_txt"
             android:layout_width="185dp"
             android:layout_height="185dp"

             android:layout_alignParentTop="true"
             android:layout_marginTop="163dp"
             android:background="@drawable/bg_red"
             android:gravity="center"
             android:text="My name is NON"
             android:textColor="#FFFFFF"
             android:layout_marginLeft="10dp"
             android:textSize="10dp" />

         <TextView
             android:id="@+id/TextView02"
             android:layout_width="90dp"
             android:layout_height="90dp"
             android:layout_alignParentRight="true"
             android:layout_alignTop="@+id/TextView01"
             android:layout_marginRight="90dp"
             android:layout_marginTop="122dp"
             android:background="@drawable/bg_red"
             android:gravity="center"
             android:text="My name is NON"
             android:textColor="#FFFFFF"
             android:textSize="10dp" />

         <TextView
             android:id="@+id/TextView01"
             android:layout_width="120dp"
             android:layout_height="120dp"
             android:layout_alignTop="@+id/num_txt"
             android:layout_toRightOf="@+id/num_txt"
             android:background="@drawable/bg_red"
             android:gravity="center"
             android:text="My name is NON"
             android:textColor="#FFFFFF"
             android:textSize="10dp" />

    </RelativeLayout>

ConstraintLayout use for badge count.

enter image description here

    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent"
        android:gravity="center">

        <ImageView
            android:id="@+id/tab_icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:background="@android:color/transparent"
            android:scaleType="centerInside"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@drawable/ic_home"
            tools:layout_constraintBottom_creator="1"
            tools:layout_constraintLeft_creator="1"
            tools:layout_constraintRight_creator="1"
            tools:layout_constraintTop_creator="1" />

        <TextView
            android:id="@+id/tab_badge"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:background="@drawable/icon_badge"
            android:paddingBottom="1dp"
            android:paddingLeft="6dp"
            android:paddingRight="6dp"
            android:paddingTop="1dp"
            android:text="10"
            android:textAppearance="@style/TextAppearance.AppCompat.Small"
            android:textColor="@android:color/white"
            android:textSize="12dp"
            app:layout_constraintBottom_toBottomOf="@+id/tab_icon"
            tools:layout_constraintLeft_creator="1"
            android:layout_marginLeft="14dp"
            app:layout_constraintLeft_toLeftOf="@+id/tab_icon" />
    </android.support.constraint.ConstraintLayout>

Leave a Comment