//
/*Fresco的基础依赖*/ compile 'com.facebook.fresco:fresco:0.14.1' /*仅支持 WebP 静态图*/ compile 'com.facebook.fresco:webpsupport:0.14.1' /*支持 GIF 动图,需要添加*/ compile 'com.facebook.fresco:animated-gif:0.14.1' failureImage 设置网络请求失败的站位图属性xmlns:fresco="http://schemas.android.com/apk/res-auto" 设置本地图片 fresco:roundAsCircle="true" fresco:placeholderImage="@drawable/x_wd_b"入口函数
Fresco.initialize(this); //创建参数对象 设置其样式为进度条 GenericDraweeHierarchy hierarchy=builder.setProgressBarImage(new ProgressBarDrawable()).build(); 创建一个对象用于设置图片样式
GenericDraweeHierarchyBuilder builder=new GenericDraweeHierarchyBuilder(getResources());
Uri uri=Uri.parse("https://m.360buyimg.com/n0/jfs/t8830/106/1760940277/195595/5cf9412f/59bf2ef5N5ab7dc16.jpg"); GenericDraweeHierarchy draweeHierarchy=builder.setActualImageScaleType(ScalingUtils.ScaleType.CENTER_INSIDE).build(); 给图片设置样式 和地址
simple.setHierarchy(draweeHierarchy); simple.setImageURI(uri);
设置圆角图片
GenericDraweeHierarchyBuilder builder=new GenericDraweeHierarchyBuilder(getResources());
RoundingParams pro=RoundingParams.fromCornersRadius(150f);
GenericDraweeHierarchy yuan= builder.setRoundingParams(pro).build(); simpleyuan.setHierarchy(yuan); simpleyuan.setImageURI(uri);
设置GIF图
通过Controller对象设置GIF动图
DraweeController draweeController= Fresco.newDraweeControllerBuilder() .setUri(uri2) .setAutoPlayAnimations(false) .build(); simplegif.setController(draweeController);
设置动图开始或者暂停
在点击事件中
拿到动画对象
Animatable animatable=simplegif.getController().getAnimatable(); if(animatable!=null&&!animatable.isRunning()){ animatable.start(); }
停止
animatable1.stop();