注:還有許多其他功能路星,可查看官方文檔橄唬。
1.在application中初始化:Fresco.initialize(this);
2.使用SimpleDraweeView代替ImageView赎瞎,同時(shí)Fresco不支持wrap_content屬性揍很,必須有明確的寬和高
在使用SimpleDraweeView時(shí),最好一個(gè)imageview的屬性都不要在使用
3.SimpleDraweeView的屬性設(shè)置:
在布局文件中設(shè)置:
fresco:placeholderImage="@mipmap/icon_placeholder"http://設(shè)置占位圖
fresco:placeholderImageScaleType="fitCenter"http://設(shè)置占位圖片縮放類型
fresco:actualImageScaleType="focusCrop"http://實(shí)際圖片縮放類型
fresco:progressBarImage="@mipmap/icon_progress_bar"http://正在加載的圖片
fresco:progressBarImageScaleType="centerInside"http://正在加載圖片的縮放類型
fresco:progressBarAutoRotateInterval="5000"http://正在加載圖的旋轉(zhuǎn)間隔辆雾,直到實(shí)際圖加載完畢
fresco:failureImage="@mipmap/icon_failure"http://加載失敗顯示的圖片
fresco:failureImageScaleType="centerInside"http://失敗顯示的圖片的類型
fresco:retryImage="@mipmap/icon_retry"http://失敗重試的圖片------和加載失敗的圖片一起設(shè)置肪笋,當(dāng)失敗一定次數(shù)后不顯示重試圖片,顯示加載失敗圖片
fresco:retryImageScaleType="centerCrop"http://失敗重試的圖片的縮放類型
fresco:fadeDuration="5000"http://淡進(jìn)淡出動畫時(shí)間度迂,毫秒
fresco:backgroundImage="@android:color/holo_orange_light"http://背景圖
//疊加圖顯示在最上面
fresco:pressedStateOverlayImage="@android:color/holo_green_dark"http://按壓下顯示的疊加圖
fresco:overlayImage="@android:color/black"http://疊加圖
//同時(shí)設(shè)置圓形和圓角時(shí)藤乙,顯示為圓形圖
fresco:roundAsCircle="true"http://是否是圓形圖
fresco:roundedCornerRadius="30dp"http://設(shè)置圓角半徑
//分別設(shè)置4個(gè)角是否是圓形圖
fresco:roundTopLeft="true"
fresco:roundTopRight=""
fresco:roundBottomLeft=""
fresco:roundBottomRight=""
//給圓形圖加邊框
fresco:roundingBorderWidth="10dp"http://設(shè)置邊框?qū)挾?br>
fresco:roundingBorderColor="@android:color/black"http://設(shè)置邊框顏色
fresco:roundWithOverlayColor="@android:color/darker_gray"http://圓形和圓角圖的疊加顏色,就是在方形控件惭墓,圖片空白區(qū)域顯示的顏色
注意:不能直接設(shè)置實(shí)際需要顯示的圖片坛梁,但是可以設(shè)置占位圖,作為圖片顯示
使用失敗重試時(shí)腊凶,需要設(shè)置DraweeController :
//創(chuàng)建DraweeController
DraweeController controller = Fresco.newDraweeControllerBuilder()
//加載的圖片URI地址
.setUri(imageUri)
//設(shè)置點(diǎn)擊重試是否開啟
.setTapToRetryEnabled(true)
//設(shè)置舊的Controller划咐,可以減少不必要的浪費(fèi)
.setOldController(simpleDraweeView.getController())
//構(gòu)建
.build();
//設(shè)置DraweeController
simpleDraweeView.setController(controller);
XML屬性 意義
fadeDuration 淡入淡出動畫持續(xù)時(shí)間(單位:毫秒ms)
actualImageScaleType 實(shí)際圖像的縮放類型
placeholderImage 占位圖
placeholderImageScaleType 占位圖的縮放類型
progressBarImage 進(jìn)度圖
progressBarImageScaleType 進(jìn)度圖的縮放類型
progressBarAutoRotateInterval 進(jìn)度圖自動旋轉(zhuǎn)間隔時(shí)間(單位:毫秒ms)
failureImage 失敗圖
failureImageScaleType 失敗圖的縮放類型
retryImage 重試圖
retryImageScaleType 重試圖的縮放類型
backgroundImage 背景圖
overlayImage 疊加圖
pressedStateOverlayImage 按壓狀態(tài)下所顯示的疊加圖
roundAsCircle 設(shè)置為圓形圖
roundedCornerRadius 圓角半徑
roundTopLeft 左上角是否為圓角
roundTopRight 右上角是否為圓角
roundBottomLeft 左下角是否為圓角
roundBottomRight 右下角是否為圓角
roundingBorderWidth 圓形或者圓角圖邊框的寬度
roundingBorderColor 圓形或者圓角圖邊框的顏色
roundWithOverlayColor 圓形或者圓角圖底下的疊加顏色(只能設(shè)置顏色)
viewAspectRatio 控件縱橫比
縮放類型—ScaleType:
類型 描述
center 居中拴念,無縮放
centerCrop 保持寬高比縮小或放大,使得兩邊都大于或等于顯示邊界褐缠。居中顯示政鼠。
focusCrop 同centerCrop, 但居中點(diǎn)不是中點(diǎn),而是指定的某個(gè)點(diǎn)
centerInside 使兩邊都在顯示邊界內(nèi)队魏,居中顯示公般。如果圖尺寸大于顯示邊界,則保持長寬比縮小圖片胡桨。
fitCenter 保持寬高比官帘,縮小或者放大,使得圖片完全顯示在顯示邊界內(nèi)登失。居中顯示
fitStart 同上遏佣。但不居中挖炬,和顯示邊界左上對齊
fitEnd 同fitCenter揽浙, 但不居中,和顯示邊界右下對齊
fitXY 不保存寬高比意敛,填充滿顯示邊界
none 如要使用tile mode顯示, 需要設(shè)置為none
推薦使用:focusCrop 類型馅巷,可以在代碼中通過mSimpleDraweeView.getHierarchy();然后setActualImageFocusPoint設(shè)置中心點(diǎn)
4.在代碼中可以設(shè)置的:
需要在代碼中修改占位圖等東西需要使用mSimpleDraweeView.getHierarchy()來修改。
顯示Gif
a.設(shè)置Gif圖片自動播放
Uri uri;
DraweeController controller = Fresco.newDraweeControllerBuilder()
.setUri(uri)
.setAutoPlayAnimations(true)
. // 其他設(shè)置(如果有的話)
.build();
mSimpleDraweeView.setController(controller);
b.手動控制動畫圖播放
5.混淆
a.在gradle中添加:
android {
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-fresco.pro'
}
}
}
b.在混淆文件中添加
Keep our interfaces so they can be used by other ProGuard rules.
See http://sourceforge.net/p/proguard/bugs/466/
-keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip
Do not strip any method/class that is annotated with @DoNotStrip
-keep @com.facebook.common.internal.DoNotStrip class *
-keepclassmembers class * {
@com.facebook.common.internal.DoNotStrip *;
}
Keep native methods
-keepclassmembers class * {
native <methods>;
}
-dontwarn okio.**
-dontwarn com.squareup.okhttp.**
-dontwarn okhttp3.**
-dontwarn javax.annotation.**
-dontwarn com.android.volley.toolbox.**
Works around a bug in the animated GIF module which will be fixed in 0.12.0
-keep class com.facebook.imagepipeline.animated.factory.AnimatedFactoryImpl {
public AnimatedFactoryImpl(com.facebook.imagepipeline.bitmaps.PlatformBitmapFactory,com.facebook.imagepipeline.core.ExecutorSupplier);
}