鍍金池/ 教程/ Android/ 動(dòng)畫圖(gif)
進(jìn)度條
在JAVA代碼中使用Drawees
Drawee的各種效果配置
緩存
一些陷阱
關(guān)于在Android Studio中編譯
多圖請(qǐng)求及圖片復(fù)用
自定義網(wǎng)絡(luò)加載
支持的URIs
可關(guān)閉的引用
監(jiān)聽下載事件
修改圖片
引入Fresco
縮放
圓角和圓圈
配置Image Pipeline
縮放和旋轉(zhuǎn)圖片
(圖片請(qǐng)求)Image Requests
自定義View
使用ControllerBuilder
在XML中使用Drawees
開始使用 Fresco
關(guān)鍵概念
Image Pipeline介紹
漸進(jìn)式JPEG圖
數(shù)據(jù)源和數(shù)據(jù)訂閱者
直接使用Image Pipeline
動(dòng)畫圖(gif)
使用其他的Image Loader

動(dòng)畫圖(gif)

本教程內(nèi)容來源于:http://fresco-cn.org
采用 知識(shí)共享 署名 4.0 國際 許可協(xié)議 進(jìn)行許可

Fresco 支持GIF和WebP 格式圖片;支持WebP 格式的動(dòng)畫圖也支持(包括擴(kuò)展WebP 格式),支持2.3及其以后那些沒有原生WebP支持的系統(tǒng)。

設(shè)置動(dòng)畫圖自動(dòng)播放

如果你希望圖片下載完之后自動(dòng)播放,同時(shí),當(dāng)View從屏幕移除時(shí),停止播放,只需要在image request 中簡單設(shè)置,如下:

Uri uri;
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri)
    .setAutoPlayAnimation(true)
    . // other setters
    .build();

DraweeController controller = Fresco.newDraweeControllerBuilder()
    .setImageRequest(request)
    . // other setters
    .build();
mSimpleDraweeView.setController(controller);

手動(dòng)控制動(dòng)畫圖播放

也許,你希望在圖片加載完之后,手動(dòng)控制動(dòng)畫的播放,那么這樣做:

ControllerListener controllerListener = new BaseControllerListener() {
    @Override
    public void onFinalImageSet(
        String id,
        @Nullable ImageInfo imageInfo,
        @Nullable Animatable anim) {
    if (anim != null) {
      // 根據(jù)業(yè)務(wù)邏輯,在合適的時(shí)機(jī)播放動(dòng)畫。
    }
};

Uri uri;
PipelineDraweeController controller = Fresco.newControllerBuilder()
    .setControllerListener(controllerListener)
    .setUri(uri);
    // other setters
    .build();
mSimpleDraweeView.setController(controller);

另外,controller提供對(duì)Animatable 的訪問。

如果有可用動(dòng)畫的話,可對(duì)動(dòng)畫進(jìn)行靈活的控制:

Animatable animation = mSimpleDraweeView.getController().getAnimatable();
if (animation != null) {
  // 開始播放
  animation.start();
  // 一段時(shí)間之后,根據(jù)業(yè)務(wù)邏輯,停止播放
  animation.stop();
}