-3

I have been trying to create a circular image view. any help will be greatly appreciated.

Anita
  • 49
  • 2
  • 11
  • Take a look at these two answers http://stackoverflow.com/questions/2459916/how-to-make-an-imageview-to-have-rounded-corners http://stackoverflow.com/questions/16208365/create-circular-image-view-in-android – TheBaj Jul 03 '14 at 23:00

2 Answers2

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" />
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