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.

To use it in XML, simply do it like this:

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.

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.

In Android, the Canvas class has a method called drawRoundRect() that you can use to draw rounded corners on the edges of a drawn rectangle.

I would like to emphasize that using a value of 1 for both 2nd and 3rd parameters will not give you rounded corners. At least use 3.

Here is a sample code

This code draws a black colored rectangle and fills it using the same color.

Related Posts Plugin for WordPress, Blogger...