国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

SimpleCommand框架ImageLoader API詳解(三)

2019-12-12 01:51:34
字體:
供稿:網(wǎng)友

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)。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 重庆市| 元江| 敦煌市| 高阳县| 正定县| 辽阳县| 沾化县| 东方市| 沂水县| 彩票| 彭泽县| 东兰县| 岑溪市| 洪雅县| 大埔县| 察隅县| 育儿| 定安县| 井研县| 盱眙县| 玛曲县| 九龙县| 萨嘎县| 东至县| 陆良县| 方城县| 沙田区| 响水县| 苍梧县| 讷河市| 塔城市| 宣威市| 印江| 高青县| 吴旗县| 灌阳县| 台南县| 游戏| 融水| 教育| 永和县|