一、webpdecoder 源码
https://github.com/zjupure/GlideWebpDecoder
二、 引入
// webpdecoder
implementation "com.github.zjupure:webpdecoder:2.0.4.13.1"
// glide 4.10.0+
implementation "com.github.bumptech.glide:glide:4.13.1"
annotationProcessor "com.github.bumptech.glide:compiler:4.13.1"
三、 布局
<ImageView
android:id="@+id/iv_load"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:layout_marginTop="30dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:id="@+id/iv_order_click"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
四、 使用
var ivLoad = findViewById<ImageView>(R.id.iv_load)
var ivOrderClick = findViewById<ImageView>(R.id.iv_order_click)
var circleCrop = CenterInside()
ivOrderClick.setOnClickListener {
Toast.makeText(this, "点击了小手跳转", Toast.LENGTH_SHORT).show()
}
Glide.with(this).load(R.mipmap.iv_load_guide).optionalTransform(circleCrop)
.optionalTransform(WebpDrawable::class.java, WebpDrawableTransformation(circleCrop))
.addListener(object : RequestListener<Drawable> {
override fun onLoadFailed(
e: GlideException?,
model: Any?,
target: Target<Drawable>?,
isFirstResource: Boolean
): Boolean {
return false
}
override fun onResourceReady(
resource: Drawable?,
model: Any?,
target: Target<Drawable>?,
dataSource: DataSource?,
isFirstResource: Boolean
): Boolean {
var webpDrawable = (resource as WebpDrawable)
//设置循环次数
webpDrawable.loopCount = 1
//动画开始结束监听
webpDrawable.registerAnimationCallback(object :
Animatable2Compat.AnimationCallback() {
override fun onAnimationStart(drawable: Drawable?) {
super.onAnimationStart(drawable)
}
override fun onAnimationEnd(drawable: Drawable?) {
super.onAnimationEnd(drawable)
Glide.with(this@MainActivity).load(R.mipmap.iv_order_click)
.optionalTransform(circleCrop)
.optionalTransform(
WebpDrawable::class.java,
WebpDrawableTransformation(circleCrop)
)
.into(ivOrderClick)
}
})
return false
}
})
.into(ivLoad)
}
五、 附加
https://www.csdn.net/tags/MtjaggzsNDgwOC1ibG9n.html
|