我正在使用带有Seekbar的自定义拇指。拇指是一个白色圆圈,后面有一个阴影,使用渐变创建。它在大多数情况下按预期工作,但是对于某些设备,我得到错误 java.lang.IllegalArgumentException:radius必须是>加载布局时:
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)
[...]
这似乎只发生在一些罕见的设备上,并且由于乱舞不能报告它们是什么(未识别),我认为它们已经扎根。
在用于创建拇指的xml下面:
<?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>
答案 0 :(得分:2)
当我使用渐变并发现棒棒糖5.0时,我遇到了这个问题,在 gradientRadius 值中存在%问题。
我有这条线:
android:gradientRadius="120%"
并将其更改为:
android:gradientRadius="120%p"
问题解决了。