第三方加载动画
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.10'
布局
<?xml version="1.0" encoding="utf-8"?>
<pl.droidsonroids.gif.GifImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/imageView"
android:scaleType="centerCrop"
android:layout_width="match_parent" android:layout_height="match_parent">
</pl.droidsonroids.gif.GifImageView>
activity实现
package com.dsy.test
import android.os.Bundle
import android.os.Handler
import android.os.Message
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_image_view.*
import pl.droidsonroids.gif.GifDrawable
import java.lang.ref.WeakReference
/**
*@Created by wrs on 2020/9/29,10:02
*@packageName: com.dsy.test
*@Description: 图片加载
*/
class ImageActivity : AppCompatActivity() {
private var handler: Handler? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_image_view)
handler = MyHandler(this)
imageView.setImageResource(R.mipmap.welcome)
val gifDrawable = imageView.drawable as? GifDrawable?
gifDrawable?.start() //开启加载
gifDrawable?.loopCount = 1 //加载几次
val duration = gifDrawable?.duration //gif动画时间
handler?.sendEmptyMessageDelayed(0,(duration ?: 3000).toLong())
}
private class MyHandler(var activity: ImageActivity?) : Handler() {
var weakReference: WeakReference<ImageActivity> = WeakReference<ImageActivity>(activity)
override fun handleMessage(msg: Message) {
super.handleMessage(msg)
if (weakReference.get() != null) {
//todo 操作
activity?.finish()
}
}
}
}
网友评论