gif android 点击 加载,Android两种简单的加载GIF图片的方法
此文介紹兩種簡單的加載GIF圖片的方法,一種是用Glide,另一種使用Fresco。
一、使用Glide加載
1.注入依賴
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
2.創(chuàng)建一個ImageView
android:id="@+id/glide_git_iv"
android:layout_width="150dp"
android:layout_height="150dp" />
3.找到對應(yīng)控件直接使用
ImageView glideGif = findViewById(R.id.glide_git_iv);
Glide.with(this).load(PIC_URL).into(glideGif);
二、使用Fresco加載
1.注入依賴
//加載fresco圖片框架
api 'com.facebook.fresco:fresco:1.10.0'
api 'com.facebook.fresco:animated-gif:1.10.0'
2.創(chuàng)建一個SimpleDraweeView
android:id="@+id/fresco_git_sdv"
android:layout_width="150dp"
android:layout_height="150dp" />
3.初始化及使用
Fresco.initialize(this);//初始化在加載布局的上面
setContentView(R.layout.git_test);
SimpleDraweeView frescoGif = findViewById(R.id.fresco_git_sdv);
DraweeController draweeController = Fresco.newDraweeControllerBuilder()
.setAutoPlayAnimations(true)
//設(shè)置uri,加載本地的gif資源
.setUri(Uri.parse(PIC_URL))
.build();
//設(shè)置Controller
frescoGif.setController(draweeController);
好,這樣GIF就可以愉快的動起來了~
總結(jié)
以上是生活随笔為你收集整理的gif android 点击 加载,Android两种简单的加载GIF图片的方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 遍历某个文件夹下的所有文件并格式化显示出
- 下一篇: android sina oauth2.