- xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fresco="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
<Button
android:id="@+id/xml_bt_xml_gif"
android:layout_width="match_parent"
android:layout_height="45dp"
android:text="gif播放/暂停"/>
<com.facebook.drawee.view.SimpleDraweeView
android:layout_width="350dp"
android:layout_height="300dp"
fresco:placeholderImage="@mipmap/android_icon"
android:id="@+id/xml_gif_iv_show"/>
</LinearLayout>
- 核心java代码
1.设置
DraweeController
的setAutoPlayAnimations(true)
为true,自动播放
draweeController= Fresco.newDraweeControllerBuilder()
.setAutoPlayAnimations(true)
.setUri(Uri.parse(uri))//设置uri
.build();
//设置Controller
simpleDraweeView.setController(draweeController);
2.控制播放
Animatable animatable=draweeController.getAnimatable();
//判断是否正在运行
if (animatable.isRunning()){
//运行中,停止
animatable.stop();
}else{
//停止了,运行
animatable.start();
}
- 效果图
时间: 2024-11-01 21:27:58