这个问题主要发生在安卓6的ImageView上,主要原因这个日志描述得比较清楚了,就是缺少一个newDrawable方法的实现。
我们在实现的Drawable中覆写一个方法:
class NumberDrawable(val context: Context, val resources: Resources) : Drawable() {
private val numberState: NumberState = NumberState(context, resources)
override fun getConstantState(): ConstantState? {
return numberState
}
}这个numberState就是我们需要实现的,具体如下:
class NumberState(val context: Context, val resources: Resources) : ConstantState() {
override fun newDrawable(): Drawable {
val drawable = NumberDrawable(context, resources)
//如果NumberDrawable有什么自定义的参数,请一并在这里进行赋值 这样产生的Drawable才不会超出你的想象
return drawable
}
override fun getChangingConfigurations(): Int = 0
}其实可以理解成处理了一个copyDrawable的行为,在安卓6以下的ImageView需要这个方法。
仅记录一下。
文章参考:https://iwyatt.cc/2017/06/14/wt-android-drawable-issue/
本站广告由 Google AdSense 提供
0条评论