I have been trying to create a circular image view. any help will be greatly appreciated.
Asked
Active
Viewed 546 times
2 Answers
1
Create a Shape Drawable resource, eg in ring.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadius="40dp"
android:shape="ring"
android:thickness="10dp"
android:useLevel="false" >
<solid android:color="#0000ff" />
<size
android:height="100dp"
android:width="100dp" />
</shape>
The api guide gives details of the various ways you can vary the dimensions of the ring but in this case note that the innerRadius+thickness=height and width. This means the ring fits exactly in the shape. It's easy to get things wrong and to have misleading shapes generated, eg if you changed the innerRadius to 50 the shape would be all hole!
To include the Shape Drawable in an ImageView use:
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="TODO"
android:src="@drawable/ring" />

user3790323
- 26
- 1
0
You can use the shape tag to create a drawable and use this
<stroke android:width="3dp"
android:color="ANY-VALID-HEX-COLOR-CODE"/>
<corners android:bottomRightRadius="some-dp"
android:bottomLeftRadius="some-dp"
android:topLeftRadius="some-dp"
android:topRightRadius="some-dp"/>
Play around with the dp values to get the circle shape. And you can also use colors for stroke to get the color you want.

Phantômaxx
- 37,901
- 21
- 84
- 115

Syed Sehu Mujammil A
- 875
- 2
- 9
- 21