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.
Create A Solid Circle Shape The property android:shape="oval" makes it a circular shape.
The <shape> element is where the shape of your drawable is defined and all its nested elements are defined. The android:shape attribute can hold four values: rectangle , oval , ring , or line . If you do not specify a value, it will be a rectangle by default.
Sometimes you want an outline around your shape and to do that you can use the stroke tag. You can specify the width and color of the outline using android:width and android:color.
A ShapeDrawable takes a Shape object and manages its presence on the screen. If no Shape is given, then the ShapeDrawable will default to a RectShape . This object can be defined in an XML file with the <shape> element.
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" />
I answer myself.
It seems the problem is in the Graphical Layout Editor of Eclipse, the code works fine in a real device.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With