There was a previous post about this where you add round corners on an ImageView widget. That code can only be used programmatically so to be able to do the same thing within an XML file, a custom class has to be made in order for this to work.

User Devunwired of StackOverflow had made a custom class that works seamlessly and easily incorporate it in your XML.

I actually forgot where I got this but if you Google it, there should be a ton of them scattered across forums posting the same method such as the one below.

While some of you may want the implementation as a custom ImageView class widget so it can be used in XML (this will be in another post), this piece of code aims to help users attain the same result through code.

Considering that widgets do not accept custom views, this method simply did the trick.

Java

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

publicstaticBitmap getRoundedCornerBitmap(Bitmap src,intradius){

intwidth=src.getWidth();

intheight=src.getHeight();

Bitmap result=Bitmap.createBitmap(width,height,Config.ARGB_8888);

Canvas canvas=newCanvas(result);

Paint paint=newPaint(Paint.ANTI_ALIAS_FLAG);

RectF rect=newRectF(0,0,width,height);

paint.setColor(Color.BLACK);

canvas.drawRoundRect(rect,radius,radius,paint);

paint.setXfermode(newPorterDuffXfermode(Mode.SRC_IN));

canvas.drawBitmap(src,0,0,paint);

paint.setXfermode(null);

returnresult;

}

The parameter radius indicates how slanted the rounded corner you want it to be. The bigger the value, the more rounded the corner will be.