Android Question Corner radius button

Blue.Sky

Active Member
Licensed User
Longtime User
Hi
I use statelistdrawable for button
I use colordrawable with radius 50 for convert button to circle
Now in many device is correct but with different dpi button not circle complete
How set radius to button for convert to circle?
 

ilan

Expert
Licensed User
Longtime User
just make sure that the height and width are the same like

btn1.height = 10%x (use %)
btn1.width = 10%x (use also x for the width to get a square)

now set the radius to 5%x (half of the width)

you should now get a circle on any device.

regards, ilan
 
Upvote 0

Blue.Sky

Active Member
Licensed User
Longtime User
just make sure that the height and width are the same like

btn1.height = 10%x (use %)
btn1.width = 10%x (use also x for the width to get a square)

now set the radius to 5%x (half of the width)

you should now get a circle on any device.

regards, ilan
Thank you
I define view's size in designer
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
you can use in designer %

then in your code you just set corner radius to btn1.widht /2
 
Last edited:
Upvote 0

MaFu

Well-Known Member
Licensed User
Longtime User
I use 50 not 50dip
You should avoid using normal values for view sizes, in all cases. Use dip and your views have (almost) the same size on all devices.
This belongs to code, designer uses dip automatically.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Also to note, any radius bigger than the half of the bigger side(x or y) will render to as if it was set to its half
 
Upvote 0

Blue.Sky

Active Member
Licensed User
Longtime User
Also to note, any radius bigger than the half of the bigger side(x or y) will render to as if it was set to its half
I adjust to View's width and height (Radius = View1.Width / 2)
 
Upvote 0
Top