欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SimpleCommand實(shí)現(xiàn)圖片下載(二)

 更新時(shí)間:2017年10月20日 09:49:48   作者:Danny_姜  
這篇文章主要為大家詳細(xì)介紹了SimpleCommand實(shí)現(xiàn)圖片下載,并顯示到ImageView控件上,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

使用simplecommand下載網(wǎng)絡(luò)圖片,并顯示到ImageView控件上。

1 在app module的build.gradle將simplecommand框架進(jìn)行導(dǎo)入,具體請(qǐng)看第1節(jié)的步驟1和2

2 設(shè)置網(wǎng)絡(luò)圖片的Url地址:這里以請(qǐng)求百度logo圖片為例

String imageUrl = "https://www.baidu.com/img/bd_logo1.png";

3 構(gòu)建圖片下載的進(jìn)度監(jiān)聽(tīng)器

ImageLoader.ProgressListener listener = new ImageLoader.ProgressListener() {
      @Override
      public void update(int percent) {
        Log.e("TAG", "percent is " + percent);
      }
    };

4 構(gòu)建ImageLoader對(duì)象,傳入進(jìn)度監(jiān)聽(tīng)器,并設(shè)置是否支持緩存

/**
 * 第一個(gè)參數(shù):Context上下文,最好使用ApplicationContext
 * 第二個(gè)參數(shù):ProgressListener,下載進(jìn)度的監(jiān)聽(tīng)器
 * 第三個(gè)參數(shù):boolean,是否支持緩存
 */
ImageLoader imageLoader = new ImageLoader(this, listener, true);

5 調(diào)用ImageLoader下載圖片,并設(shè)置到ImageView控件上

imageLoader.load(imageUrl)
      .withPlaceholder(R.mipmap.ic_launcher)
      .into(image);

簡(jiǎn)單說(shuō)明一下:

當(dāng)上面的第5步執(zhí)行之后,會(huì)打印TAG標(biāo)簽的進(jìn)度提示0 ~ 100 %
當(dāng)圖片下載成功之后,會(huì)顯示在ImageView控件上,并默認(rèn)在storage/sdcard/Android/data/packageName/cach/picass-big-cache文件夾下保存圖片緩存數(shù)據(jù)

框架github地址: SimpleCommand框架

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論