ImageLoader API 詳細(xì)介紹,具體內(nèi)容如下
在ImageLoader中有以下幾個不同的構(gòu)造器:
/** * 注意: 次構(gòu)造器不支持下載進(jìn)度提示功能 * @param context * @param withCache 是否支持緩存 * false--不帶緩存 * true--支持緩存功能,默認(rèn)緩存路徑在外置存儲緩沖目錄中的picasso-big-cache文件夾中 */ public ImageLoader(Context context, boolean withCache) { this(context, null, withCache); } /** * 支持下載進(jìn)度提示,以及設(shè)置緩存路徑 * @param context * @param listener 下載進(jìn)度監(jiān)聽器 * @param cachePath 緩存路徑字符串 */ public ImageLoader(Context context, ProgressListener listener, String cachePath) { // TODO extend to support multiple libraries as Glide // TODO must be initialized and kept as an member instance to avoid losing cache Picasso.Builder builder = setupLoaderClientWithCachePath(context, listener, cachePath); setupListener(builder); picasso = builder.build(); picasso.setIndicatorsEnabled(BuildConfig.DEBUG); picasso.setLoggingEnabled(BuildConfig.DEBUG); } /** * 支持下載進(jìn)度提示,以及設(shè)置緩存路徑為默認(rèn)路徑picasso-big-cache * @param context * @param listener 下載進(jìn)度監(jiān)聽器 * @param withCache 是否支持緩存 */ public ImageLoader(Context context, ProgressListener listener, boolean withCache) { // TODO extend to support multiple libraries as Glide // TODO must be initialized and kept as an member instance to avoid losing cache Picasso.Builder builder = setupLoaderClient(context, listener, withCache); setupListener(builder); picasso = builder.build(); picasso.setIndicatorsEnabled(BuildConfig.DEBUG); picasso.setLoggingEnabled(BuildConfig.DEBUG); }public void shutdown() { if (picasso == null) return; Logger.d(Logger.TAG, "Image loader has been shutdown"); picasso.shutdown(); callback = null; }將ImageLoader停止,一般在Activity停止,或者任務(wù)結(jié)束時調(diào)用此方法將其關(guān)閉
public ImageLoader cancelRequest(ImageView imageView) { picasso.cancelRequest(imageView); return this; }取消之前顯示到ImageView上的請求
public ImageLoader load(final int resourceId) { cleanResources(); this.imageResourceId = resourceId; return this; }public ImageLoader load(final String imageUri) { cleanResources(); this.imageUri = imageUri; return this; }分別加載本地drawable文件夾下的圖片,以及網(wǎng)絡(luò)圖片
public ImageLoader withPlaceholder(final int placeholder) { this.placeholder = placeholder; return this; }設(shè)置ImageLoader下載圖片時的預(yù)覽圖
public ImageLoader withErrorImage(final int errorImage) { this.errorImage = errorImage; return this; }下載圖片失敗時顯示的圖片
public ImageLoader withTag(final String tag) { this.tag = tag; return this; }public void pause(final String tag) { if (picasso == null) return; picasso.pauseTag(tag); }public void resume(final String tag) { if (picasso == null) return; picasso.resumeTag(tag); }以上三個方法依次是
1 下載圖片時添加標(biāo)簽tag
2 暫停tag標(biāo)簽的下載任務(wù)
3 resume tag標(biāo)簽的下載任務(wù)
public ImageLoader withCallback(final Callback callback) { this.callback = callback; return this; }給ImageLoader設(shè)置下載完成的回調(diào),包含onSuccess和onFailed方法
public ImageLoader fit() { this.fit = true; return this; } public ImageLoader centerCrop() { this.centerCrop = true; return this; } public ImageLoader centerInside() { this.centerInside = true; return this; } public ImageLoader resize(final int widthResId, final int heightResId) { this.widthResId = widthResId; this.heigthResId = heightResId; return this; }分別設(shè)置Picasso下載圖片時的相應(yīng)屬性, 可以參考ImageView的scaleType屬性
public void into(final ImageView imageView) { run(imageView); }into方法調(diào)用內(nèi)部run方法,并啟動下載任務(wù)。 此方法需要在以上所有的API之后調(diào)用。
框架github地址: SimpleCommand框架
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。
新聞熱點
疑難解答
圖片精選