Glide加载webp动画及监听动画播放结束
Posted 黄毛火烧雪下
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Glide加载webp动画及监听动画播放结束相关的知识,希望对你有一定的参考价值。
一、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
以上是关于Glide加载webp动画及监听动画播放结束的主要内容,如果未能解决你的问题,请参考以下文章
Android-Glide 4.0+ 加载GIF并控制播放次数