鍍金池/ 教程/ Android/ 自定義網(wǎng)絡(luò)加載
進(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

自定義網(wǎng)絡(luò)加載

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

Image pipeline 默認(rèn)使用HttpURLConnection。應(yīng)用可以根據(jù)自己需求使用不同的網(wǎng)絡(luò)庫。

OkHttp

OkHttp 是一個(gè)流行的開源網(wǎng)絡(luò)請(qǐng)求庫。Image pipeline有一個(gè)使用OkHttp替換掉了Android默認(rèn)的網(wǎng)絡(luò)請(qǐng)求的補(bǔ)充。

如果需要使用OkHttp, 不要使用這個(gè)下載頁面的gradle依賴配置,應(yīng)該使用下面的依賴配置

dependencies {
  // your project's other dependencies
  compile: "com.facebook.fresco:drawee:0.1.0+"
  compile: "com.facebook.fresco:imagepipeline-okhttp:0.1.0+"
}

配置Image pipeline這時(shí)也有一些不同,不再使用ImagePipelineConfig.newBuilder,而是使用OkHttpImagePipelineConfigFactory:

Context context;
OkHttpClient okHttpClient; // build on your own
ImagePipelineConfig config = OkHttpImagePipelineConfigFactory
    .newBuilder(context, okHttpClient)
    . // other setters
    . // setNetworkFetchProducer is already called for you
    .build();
Fresco.initialize(context, config);

使用自定的網(wǎng)絡(luò)層

For complete control on how the networking layer should behave, you can provide one for your app. You must subclass 為了完全控制網(wǎng)絡(luò)層的行為,你可以自定義網(wǎng)絡(luò)層。繼承NetworkFetchProducer, 這個(gè)類包含了網(wǎng)絡(luò)通信。

你也可以選擇性地繼承NfpRequestState, 這個(gè)類是請(qǐng)求時(shí)的數(shù)據(jù)結(jié)構(gòu)描述。

默認(rèn)的 HttpURLConnection 可以作為一個(gè)參考. 源碼在這 its source code.

配置Image pipeline時(shí),把producer傳遞給Image pipeline。

ImagePipelineConfig config = ImagePipelineConfig.newBuilder()
  .setNetworkFetchProducer(myNetworkFetchProducer);
  . // other setters
  .build();
Fresco.initialize(context, config);