<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          ImageLoaderSampleImageView異步加載圖片

          聯(lián)合創(chuàng)作 · 2023-09-24 11:01

          這個可以實現(xiàn)ImageView異步加載圖片,內(nèi)存緩存,文件緩存,imageview顯示圖片時增加淡入淡出動畫。

          解決了:

          1. listview加載oom問題

          2. listview加載時卡頓的現(xiàn)象

          3. listview加載時item中圖片重復(fù)錯位等情況

          可以配置:

          1. 設(shè)置加載圖片的最大尺寸

          2. 設(shè)置默認(rèn)圖片的顯示

          3. 設(shè)置圖片位圖模式

          4. 設(shè)置內(nèi)存緩存的最大值。

          5. 文件緩存保存的目錄

            這個框架基本的代碼是很久以前不知道哪里弄的,零零碎碎的,現(xiàn)在已經(jīng)優(yōu)化了很多,所以現(xiàn)在上傳到github上共享。

            講講使用方式吧:

           

          首先使用前下載源碼或者jar包(見github:https://github.com/wangjiegulu/ImageLoaderSample

          然后進行圖片加載器(ImageLoader)的配置和初始化,推薦的方法如下:

          新建MyApplication類,繼承Application,在onCreate中增加如下代碼:

           

          /**
           * Created with IntelliJ IDEA.
           * Author: wangjie  email:[email protected]
           * Date: 14-2-27
           * Time: 上午11:25
           */
          public class MyApplication extends Application{
              @Override
              public void onCreate() {
                  super.onCreate();
                  ImageLoader.init(getApplicationContext(),
                          new CacheConfig()
                              .setDefRequiredSize(600) // 設(shè)置默認(rèn)的加載圖片尺寸(表示寬高任一不超過該值,默認(rèn)是70px)
                              .setDefaultResId(R.drawable.ic_launcher) // 設(shè)置顯示的默認(rèn)圖片(默認(rèn)是0,即空白圖片)
                              .setBitmapConfig(Bitmap.Config.ARGB_8888) // 設(shè)置圖片位圖模式(默認(rèn)是Bitmap.CacheConfig.ARGB_8888)
                              .setMemoryCachelimit(Runtime.getRuntime().maxMemory() / 3) // 設(shè)置圖片內(nèi)存緩存大?。J(rèn)是Runtime.getRuntime().maxMemory() / 4)
          //                  .setFileCachePath(Environment.getExternalStorageDirectory().toString() + "/mycache") // 設(shè)置文件緩存保存目錄
                  );
          
              }
          
          
              ……
          }

          然后再AndroidManifest.xml中添加:

           

           

          ......

          到此,配置已經(jīng)全部完成:

          接下來,使用ImageLoader來加載圖片:

          holder.progress.setText("0%");
              holder.progress.setVisibility(View.VISIBLE);
              final ViewHolder vhr = holder;
              ImageLoader.getInstances().displayImage(list.get(position), holder.image, new ImageLoader.OnImageLoaderListener() {
                  @Override
                  public void onProgressImageLoader(ImageView imageView, int currentSize, int totalSize) {
                      vhr.progress.setText(currentSize * 100 / totalSize + "%");
                  }
          
                  @Override
                  public void onFinishedImageLoader(ImageView imageView, Bitmap bitmap) {
                      vhr.progress.setVisibility(View.GONE);
                  }
              });
              或者:
              ImageLoader.getInstances().displayImage(url, imageIv);
              或者
              ImageLoader.getInstances().displayImage(url, imageIv, 100);

          備注:
          例子中,用到了一部分注解(與ImageLoader功能無關(guān),但是可以簡化代碼的編寫) 可以點下面連接進入:
          github:https://github.com/wangjiegulu/androidInject
          博客:
          http://www.cnblogs.com/tiantianbyconan/p/3459139.html
          http://www.cnblogs.com/tiantianbyconan/p/3540427.html

           

          瀏覽 16
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  欧美日韩国产在线播放 | 成人网站三级在线视频网站 | 免费在线观看黄色 | 大香蕉中文网 | 蜜桃操逼网站 |