Manikanta Reddy
Manikanta Reddy

Reputation: 641

How to implement circle shape for textview in android?

how to show to circle shape in textview

i done the xml like

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

    <corners android:radius="2dip" />

    <stroke
        android:width="2dip"
        android:color="#FF0000" />

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

    <size
        android:height="25dp"
        android:width="15dp" />

</shape>

but it is showing in oval shape but i need a circle shape

Any one Help me....

Upvotes: 1

Views: 3539

Answers (2)

Rustam
Rustam

Reputation: 6515

try this : cirlce.xml in your drawable folder

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
 android:shape="oval" >
    <gradient android:startColor="@color/red_color"
              android:endColor="@color/red_color"
              android:angle="360"/>
</shape>

now set drawable background to your TextView.

  <TextView
    android:id="@+id/txtView"
    android:layout_width="20dip"
    android:layout_height="20dip"
    android:layout_marginTop="5dip"
    android:layout_marginRight="5dip"
    android:background="@drawable/circle"  <!-- circle drawable background.-->
    android:text="5"
    android:gravity="center"
    android:textColor="@color/white_color"
    android:textSize="10sp"
    />

Upvotes: 1

Hayuki
Hayuki

Reputation: 611

To make a circle shape, both width and height need to be the same. In your xml the <size> tag specifies height bigger than width, hence the oval. The following code will make it show up as a circle:

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

    <corners android:radius="2dip" />

    <stroke
        android:width="2dip"
        android:color="#FF0000" />

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

    <size
        android:height="25dp"
        android:width="25dp" />

</shape>

Upvotes: 0

Related Questions