Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the range for rounded corner radius?

I know how to use rounded corner for a view would be something like this:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="10dp"/>
</shape>

What is the range for radius? Is it 0 to 100 dp?

like image 342
Xi Wei Avatar asked Nov 03 '15 16:11

Xi Wei


3 Answers

There is no "range". Dp means device pixels. So if your view is 100dp the normal range would be from 0 to 50 (since setting a border radius larger than half of the width or height it would look rather weird).

But basically there is no limit.

Also taking into account that values above half the size will be treated like half the size (so a border radius of 1000dp on a 100dp image will still be only 50dp border.)
And values below zero are the same as zero.

This gives you a nice option to always have completely round borders by defining a very large radius (hacky).

like image 60
Bas van Stein Avatar answered Oct 20 '22 06:10

Bas van Stein


There is no range. You can have any value as the radius, negative or positive values.

Negative values ( like -40dp ) has no effect on the corner radius. This is same as giving corner radius as 0dp.
Positive values ( like 40dp ) has an effect, but only up to half the size of the view. Anything more than that, then it remains the same. If the height of the view is 200dp, then corner radius of 200dp behaves the same way as 100dp.

like image 1
Henry Avatar answered Oct 20 '22 06:10

Henry


As other guys already said, there's no range for android:radius property.

However, I'd suspect that you would need a round/circular shape independent of its size (width and height). If I'm right, you could use oval type shapes:

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="oval" >
    <gradient
        android:startColor="#FFFF0000"
        android:endColor="#80FF00FF"
        android:angle="270"/>
</shape>

Using this way you should make sure alpha channel of startColor is 00.

like image 1
frogatto Avatar answered Oct 20 '22 05:10

frogatto