测试项目的时候遇到一个问题。

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.view.View.draw(View.java:14511)
        at android.view.View.getDisplayList(View.java:13423)
        at android.view.View.getDisplayList(View.java:13465)
        at android.view.View.draw(View.java:14243)
        ...

这个问题在android 5.0以上不会出现,是在4.4的手机上出现的。由于这个问题,导致应用直接崩溃。

从Google上搜索这个问题,有两种可能会导致这个问题的出现:

1.自定义shape时 gradientRadius属性 设置问题

使用百分比设置gradientRadius属性时会抛出该异常,需要将100%修改成100%p才行。

2.CardView圆角设置问题

当设置app:cardCornerRadius="0dp"时,会抛出IllegalArgumentException: radius must be > 0的异常。

 

因为项目中没有用到CardView,那么就很可能是自定义shape的问题了。拿着gradientRadius属性全局搜索,立马找到问题所在了

报错:IllegalArgumentException: radius must be > 0

可以看到,还真是这个属性的问题。

好吧,我最后索性不用渐变的方式了

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <solid android:color="#ffe2e2e2"/>
</shape>

然后在4.4手机上就可以完美运行了,当然,5.0以上更没问题了。

相关文章:

  • 2021-10-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-18
  • 2022-01-24
  • 2021-08-11
猜你喜欢
  • 2022-12-23
  • 2021-05-16
  • 2021-04-21
  • 2022-12-23
  • 2021-05-20
  • 2022-12-23
相关资源
相似解决方案