Question: I have an ImageView and I want to make it with `rounded corners`.

I use this: 

```
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> 
    <solid  android:color="@null"/>    

    <stroke android:width="1dp"
            android:color="#ff000000"/>

    <corners android:radius="62px"/> 
</shape>

```

And set this code as background of my imageview.
It works, but the src image that I put on the `ImageView` is going out of the borders and doesn't adapt itself into the new shape.

How can I solve the problem?

Answer: 
try this one : 

```
public class CustomImageView extends ImageView {

    public static float radius = 18.0f;  

    public CustomImageView(Context context) {
        super(context);
    }

    public CustomImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomImageView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        //float radius = 36.0f;  
        Path clipPath = new Path();
        RectF rect = new RectF(0, 0, this.getWidth(), this.getHeight());
        clipPath.addRoundRect(rect, radius, radius, Path.Direction.CW);
        canvas.clipPath(clipPath);
        super.onDraw(canvas);
    }
}

```

and 

```
<your.pack.name.CustomImageView
                android:id="@+id/selectIcon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:scaleType="centerCrop" />

CustomImageView  iconImage = (CustomImageView )findViewById(R.id.selectIcon);
iconImage.setImageBitmap(bitmap);

```

or,

```
ImageView iv= new CustomImageView(this);
iv.setImageResource(R.drawable.pic);

```
The accepted answer uses path clipping, but it doesn't support anti-aliasing. See Romain Guy's comments on his post. "path clipping does not support antialiasing and you get jagged edges." 

<http://www.curious-creature.com/2012/12/11/android-recipe-1-image-with-rounded-corners/>

There is one good library(vinc3m1’s RoundedImageView) that supoorts rounded corners on ImageView, but it only supports the same radiuses on every corners. So I made one that you can set different radiuses on each corners.

It doesn't rely on path clipping, nor redrawing. It only draws one time with `canvas.drawPath()` method. So I finally got result that I wanted like below.

![enter image description here](https://i.stack.imgur.com/QzmsW.png)

See : <https://github.com/pungrue26/SelectableRoundedImageView>