Android Question Round corners

wonder

Expert
Licensed User
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
Licensed User
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:
Upvote 0

derez

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

klaus

Expert
Licensed User
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 !
 
Upvote 0

wonder

Expert
Licensed User
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!! :)
 
Upvote 0

derez

Expert
Licensed User
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.
 
Upvote 0

wonder

Expert
Licensed User
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
 
Upvote 0
Top