wonder Expert Licensed User Longtime User Nov 16, 2014 #1 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. Click to expand... Last edited: Nov 16, 2014
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. Click to expand...
derez Expert Licensed User Longtime User Nov 16, 2014 #2 You can initialize a colordrawable and set the radius there (2%x in the code below, can be by dip etc.). Code: Copy 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: Nov 16, 2014 Upvote 0
You can initialize a colordrawable and set the radius there (2%x in the code below, can be by dip etc.). Code: Copy 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
wonder Expert Licensed User Longtime User Nov 16, 2014 #3 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... Upvote 0
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...
wonder Expert Licensed User Longtime User Nov 16, 2014 #4 ...or maybe I've always been wrong and the "degrees" part is just my imagination. Upvote 0
derez Expert Licensed User Longtime User Nov 16, 2014 #5 The radius of the corner is a distance , not angle. It works for all views that have the .Background method. Upvote 0
The radius of the corner is a distance , not angle. It works for all views that have the .Background method.
klaus Expert Licensed User Longtime User Nov 16, 2014 #6 wonder said: In the designer we're able the change the corner radius of a panel (in degrees). Click to expand... 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 said: In the designer we're able the change the corner radius of a panel (in degrees). Click to expand... 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 Licensed User Longtime User Nov 16, 2014 #7 Derez said: The radius of the corner is a distance , not angle. It works for all views that have the .Background method. Click to expand... 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: Code: Copy 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 ! Click to expand... 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 said: The radius of the corner is a distance , not angle. It works for all views that have the .Background method. Click to expand... 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: Code: Copy 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 ! Click to expand... 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 Licensed User Longtime User Nov 16, 2014 #8 So the final answer is that the roundness can be set like this: Click to expand... 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
So the final answer is that the roundness can be set like this: Click to expand... 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 Licensed User Longtime User Nov 16, 2014 #9 I understand Derez. So how do I implement this code into an existing Panel (myPanel for example)? Code: Copy Dim dr As ColorDrawable dr.Initialize(Colors.rgb(120,120,255), 2%x) calc.Background = dr Like this? Code: Copy myPanel.Background = dr Upvote 0
I understand Derez. So how do I implement this code into an existing Panel (myPanel for example)? Code: Copy Dim dr As ColorDrawable dr.Initialize(Colors.rgb(120,120,255), 2%x) calc.Background = dr Like this? Code: Copy myPanel.Background = dr
derez Expert Licensed User Longtime User Nov 16, 2014 #10 Yes. Once you perform the Background method, the panel forgets about the previous drawable it had. Upvote 0
wonder Expert Licensed User Longtime User Nov 16, 2014 #11 Thank you very much Derez!! This will sure improve my projects as I had some ideas I didn't know how to implement!! Upvote 0
Thank you very much Derez!! This will sure improve my projects as I had some ideas I didn't know how to implement!!