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

在XML中使用Drawees

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

Drawees 具有極大的可定制性。

下面的例子給出了可以配置的各種選項:

<com.facebook.drawee.view.SimpleDraweeView
    android:id="@+id/my_image_view"
    android:layout_width="20dp"
    android:layout_height="20dp"
    fresco:fadeDuration="300"
    fresco:actualImageScaleType="focusCrop"
    fresco:placeholderImage="@color/wait_color"
    fresco:placeholderImageScaleType="fitCenter"
    fresco:failureImage="@drawable/error"
    fresco:failureImageScaleType="centerInside"
    fresco:retryImage="@drawable/retrying"
    fresco:retryImageScaleType="centerCrop"
    fresco:progressBarImage="@drawable/progress_bar"
    fresco:progressBarImageScaleType="centerInside"
    fresco:progressBarAutoRotateInterval="1000"
    fresco:backgroundImage="@color/blue"
    fresco:overlayImage="@drawable/watermark"
    fresco:pressedStateOverlayImage="@color/red"
    fresco:roundAsCircle="false"
    fresco:roundedCornerRadius="1dp"
    fresco:roundTopLeft="true"
    fresco:roundTopRight="false"
    fresco:roundBottomLeft="false"
    fresco:roundBottomRight="true"
    fresco:roundWithOverlayColor="@color/corner_color"
    fresco:roundingBorderWidth="2dp"
    fresco:roundingBorderColor="@color/border_color"
  />

必須設置layout_width和layout_height

如果沒有在XML中聲明這兩個屬性,將無法正確加載圖像。

wrap_content

Drawees 不支持 wrap_content 屬性。

所下載的圖像可能和占位圖尺寸不一致,如果設置出錯圖或者重試圖的話,這些圖的尺寸也可能和所下載的圖尺寸不一致。

如果大小不一致,圖像下載完之后,假設如果是wrap_content,View將會重新layout,改變大小和位置。這將會導致界面跳躍。

固定寬高比

只有希望顯示的固定寬高比時,可以使用wrap_content。

如果希望顯示的圖片保持一定寬高比例,如果 4:3,則在XML中:

<com.facebook.drawee.view.SimpleDraweeView
    android:id="@+id/my_image_view"
    android:layout_width="20dp"
    android:layout_height="wrap_content"
    <!-- other attributes -->

然后在代碼中指定顯示比例:

mSimpleDraweeView.setAspectRatio(1.33f);