Ring shape in android

suanido picture suanido · Jun 20, 2013 · Viewed 58k times · Source

I have the following xml in drawable folder (circle_status.xml) to create a ring:

<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:innerRadius="15dp"
android:thickness="10dp"
android:useLevel="false">

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

</shape>

And insert the drawable like a background of a relativeLayout, as next:

<RelativeLayout
        android:id="@+id/RelativeLayout_Status"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:background="@drawable/circle_status" >
    </RelativeLayout>

The problem, is in the relativeLayout appear a circle not a ring.

Answer

Reinherd picture Reinherd · Jul 7, 2015

Note that a ring is an oval without a fill. Just with a stroke. And the view holding it, should be a perfect square.

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">

<stroke
    android:width="1dp"
    android:color="@color/blue" />
</shape>

And the view holding it

<ImageView
     android:layout_width="10dp"
     android:layout_height="10dp"
     android:src="@drawable/ring" />