本教程內(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)。
如果你希望圖片下載完之后自動(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)畫的播放,那么這樣做:
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();
}