百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
I

ImageLoaderSample

> 编程语言
开源

Android端用于异步加载图片,内存缓存,文件缓存,在imageview显示图片时增加淡入淡出动画

99 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

Android端用于异步加载图片,内存缓存,文件缓存,在imageview显示图片时增加淡入淡出动画

ImageLoaderSample

android端用于异步加载图片,内存缓存,文件缓存,imageview显示图片时增加淡入淡出动画。

注意:

需要添加LibraryAndroidBucket项目的支持(日志、线程、util等)的依赖,ImageLoader使用的ThreadPool,修改配置文件代码

###Gradle compile 'com.github.wangjiegulu:ImageLoaderSample:1.0.1' ###Maven

            com.github.wangjiegulu
            ImageLoaderSample
            1.0.1

初始化配置

创建MyApplication 继承Application,在onCreate中增加如下代码:

        /**
         * Created with IntelliJ IDEA.
         * Author: wangjie  email:[email protected]
         * Date: 14-2-27
         * Time: 上午11:25
         */
        public class MyApplication extends ABApplication{

        @Override
            protected void initImageLoader() {
                ImageLoader.init(getApplicationContext(),
                        new CacheConfig()
                                .setDefRequiredSize(600) // 设置默认的加载图片尺寸(表示宽高任一不超过该值,默认是70px)
                                .setDefaultResId(R.drawable.ic_launcher) // 设置显示的默认图片(默认是0,即空白图片)
                                .setBitmapConfig(Bitmap.Config.ARGB_8888) // 设置图片位图模式(默认是Bitmap.CacheConfig.ARGB_8888)
                                .setMemoryCachelimit(Runtime.getRuntime().maxMemory() / 3) // 设置图片内存缓存大小(默认是Runtime.getRuntime().maxMemory() / 4)
        //                    .setFileCachePath(Environment.getExternalStorageDirectory().toString() + "/mycache") // 设置文件缓存保存目录
                );
            }
        ......
    }

###然后再AndroidManifest.xml中添加:

            ......

加载图片的调用方式如下:

    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功能无关,但是可以简化代码的编写) 可以点下面连接进入AndroidInject AndroidInject

License

Copyright 2013 Wang Jie

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Java

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言