Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

radius must be > 0 on the thumb of a SeekBar

I am using a customized thumb with a Seekbar. The thumb is a white circle with a shadow behind created using a gradient. It works as expected in most cases, but with some devices i get the error java.lang.IllegalArgumentException: radius must be > 0 when the layout is loaded :

java.lang.IllegalArgumentException: radius must be > 0
                at android.graphics.RadialGradient.<init>(RadialGradient.java:53)
                at android.graphics.drawable.GradientDrawable.ensureValidRect(GradientDrawable.java:757)
                at android.graphics.drawable.GradientDrawable.draw(GradientDrawable.java:426)
                at android.graphics.drawable.LayerDrawable.draw(LayerDrawable.java:349)
                at android.widget.AbsSeekBar.onDraw(AbsSeekBar.java:337)
                at android.view.View.draw(View.java:14757)
                at android.view.View.getDisplayList(View.java:13617)
                at android.view.View.getDisplayList(View.java:13664)
                at android.view.View.draw(View.java:14459)
                at android.view.ViewGroup.drawChild(ViewGroup.java:3273)
                at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3091)
                at android.view.View.draw(View.java:14768)
                at android.view.View.getDisplayList(View.java:13617)
                at android.view.View.getDisplayList(View.java:13664)
                at android.view.View.draw(View.java:14459)
                at android.view.ViewGroup.drawChild(ViewGroup.java:3273)
                at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3091)
                at android.view.View.getDisplayList(View.java:13609)
                at android.view.View.getDisplayList(View.java:13664)
                at android.view.View.draw(View.java:14459)
                [...]

This only seems to happen on a some rare devices, and since flurry cannot report what they are (Unidentified), I assume they are rooted.

Below the xml used to create the thumb :

<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
 <item android:drawable="@drawable/lockscreen_thumb_shadow"/>
 <item android:drawable="@drawable/lockscreen_thumb_round"
    android:bottom="10dp"
    android:top="10dp"
    android:left="10dp"
    android:right="10dp"/>
</layer-list>

lockcreen_thumb_shadow :

            <?xml version="1.0" encoding="utf-8"?>
            <shape
                android:shape="oval"
                xmlns:android="http://schemas.android.com/apk/res/android">

                <gradient android:type="radial" android:gradientRadius="35dp"
                    android:endColor="#14009FE8"
                    android:centerColor="#96009FE8"

                    android:startColor="#009FE8"
                    android:innerRadius="20dp"
                    />

                <size android:width="70dp" android:height="70dp"/>
            </shape>

lockscreen_thumb_round :

            <?xml version="1.0" encoding="utf-8"?>

            <shape xmlns:android="http://schemas.android.com/apk/res/android"
                android:shape="oval">
                <size android:height="40dp"
                    android:width="40dp" />
                <solid android:color="@android:color/white" />
            </shape>
like image 658
Laetan Avatar asked Sep 26 '22 14:09

Laetan


1 Answers

I had this problem when i used gradient and found out that lollipop 5.0, has a problem with % in gradientRadius value.

I had this line:

android:gradientRadius="120%"

and changed it to this:

android:gradientRadius="120%p"

And the problem was solved.

like image 156
Arash Avatar answered Oct 22 '22 22:10

Arash