Fresco(各种特效)——播放gif

  • 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.设置DraweeControllersetAutoPlayAnimations(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();
    }
  • 效果图
    这里写图片描述
  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ZeroFlutter

感谢支持,请我喝杯咖啡

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值