# Android QuestionRound corners

#### wonder

##### Expert
Longtime User
Hey guys,

In the designer we're able the change the corner radius of a panel (in degrees).
It's a pretty cool feat, when set to 180 I'm getting some sweet perfectly circular panels.

My question is, how do we change this value by code?

EDIT: My (little big) mistake, the corner radius is in dip, not degrees.
Klaus said:
If you have a square view and set the corner radius to the half of the width you get a circle.

Last edited:

#### derez

##### Expert
Longtime User
You can initialize a colordrawable and set the radius there (2%x in the code below, can be by dip etc.).
B4X:
``````Dim dr As ColorDrawable
dr.Initialize(Colors.rgb(120,120,255), 2%x)
calc.Background = dr``````
You can get the existing drawable by = [name].Background

Last edited:

#### wonder

##### Expert
Longtime User
Hello Derez,

Thank you for the quick answer!

I'm not quite following.
Why would a value that should be in degrees (0-360) be in screen units?
Also I need it specifically for Panels...

#### derez

##### Expert
Longtime User
The radius of the corner is a distance , not angle.
It works for all views that have the .Background method.

#### klaus

##### Expert
Longtime User
In the designer we're able the change the corner radius of a panel (in degrees).
Are you sure ?
A radius cannot be in degrees, only in pixels.
In the Designer the value you enter is considered as a dip value.
In the code you need to use dip values to set it.
If you have a squre view and set the corner radius to the half of the width you get a circle !

#### wonder

##### Expert
Longtime User
Derez said:
The radius of the corner is a distance , not angle.
It works for all views that have the .Background method.

I see your point! Thanks for the help!
I guess I always associate round things with angles.

So the final answer is that the roundness can be set like this:

B4X:
``Panel1.Color = (Colors.ARGB(255, 255, 255), 2%x)``

Klaus said:
Are you sure ?
A radius cannot be in degrees, only in pixels.
In the Designer the value you enter is considered as a dip value.
In the code you need to use dip values to set it.
If you have a squre view and set the corner radius to the half of the width you get a circle !

Hi Klaus,

You guys are totally right!! Indeed a radius is always distance, not an angle!! Also thanks for the tip on creating circles! I will update my code ASAP!!

#### derez

##### Expert
Longtime User
So the final answer is that the roundness can be set like this:
No ! , don't mix the color property with Background property which deals with drawable. The color drawable defines both color and radius of the corner.

#### wonder

##### Expert
Longtime User
I understand Derez.

So how do I implement this code into an existing Panel (myPanel for example)?
B4X:
``````Dim dr As ColorDrawable
dr.Initialize(Colors.rgb(120,120,255), 2%x)
calc.Background = dr``````

Like this?
B4X:
``myPanel.Background = dr``

#### derez

##### Expert
Longtime User
Yes. Once you perform the Background method, the panel forgets about the previous drawable it had.

Replies
2
Views
255
Android Question Button with rounded corners
Replies
12
Views
1K
Android Code Snippet [B4X] Round clipping panel
Replies
2
Views
5K
Replies
6
Views
11K
Android Question Panel Views Rounded Corners
Replies
8
Views
6K