方案一:自定义框架的方式
依赖文件:
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.1'布局文件:
<pl.droidsonroids.gif.GifImageView android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/flash" />方案二:依托布局AppCompatImageView实现
依赖文件:
implementation 'com.github.bumptech.glide:glide:4.7.1'布局文件:
<androidx.appcompat.widget.AppCompatImageView android:id="@+id/flash_view" android:layout_width="match_parent" android:layout_height="match_parent"/>界面实现:
ImageView imageview = findViewById(R.id.flash_view); RequestOptions options = new RequestOptions() .diskCacheStrategy(DiskCacheStrategy.RESOURCE); Glide.with(getApplicationContext()).load(R.drawable.flash).apply(options).into(imageview);问题:gif尺寸不能调整,显示问题比较多,可以设置背景色遮盖尺寸问题。