方式一:Fresco加载
1.添加依赖
implementation 'com.facebook.fresco:fresco:0.12.0'
implementation 'com.facebook.fresco:animated-gif:0.12.0'
2.设置controller
simpleDraweeView=mView.findViewById(R.id.decor_content_parent1);
Uri uri = new Uri.Builder()
.scheme(UriUtil.LOCAL_RESOURCE_SCHEME)
.path(String.valueOf(R.drawable.animation))
.build();
DraweeController controller = Fresco.newDraweeControllerBuilder()
.setUri(uri)
.setAutoPlayAnimations(true)
.build();
simpleDraweeView.setController(controller);
方式二:GifImageView加载
1.添加依赖
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.2'
2.xml布局
<pl.droidsonroids.gif.GifImageView
android:src="@drawable/animation"
android:layout_width="match_parent"
android:layout_height="match_parent" />
总结:用Fresco加载本地的gif图开始的时候会很慢才渲染出来画面,而GifImageView渲染就很快了,但是GifImageView加载的图过多的话容易导致OOM。