关于ImageLoader继续研究

1.首先网络权限

2.导包

3.配置新的Manifest   加入 android:name="com.example.week3_test.MyApplication"的权限

4.关于MyApplication,暂时复制即可

    

private File file;

	@Override
	public void onCreate() {
		file = new File("path");
		// 初始化imageloader
		initImageloader();
	}

	/**
	 * 
	 */
	private void initImageloader() {

		int maxMemory = ((int) Runtime.getRuntime().maxMemory()) / 1024 / 1024;

		System.out.println("最大堆内存" + maxMemory);
		// 获得 imageLoader实例
		ImageLoader imageLoader = ImageLoader.getInstance();
		// 全局配置imageLoader的属性
		ImageLoaderConfiguration.Builder builder = new ImageLoaderConfiguration.Builder(
				this)
				.
				// 最大缓存数
				diskCacheSize(100)
				.
				// 指定加载文件的磁盘缓存路径
				
				// 指定内存缓存策略,此处是通过使用的频率,限制内存的使用
				// ) UsingFreqLimitedCache (最少被用到的对象会被删除)

				// 3) UsingAgeLimitedCache (最早被添加的对象会被删除)

				// 4) LargestLimitedCache (空间占用最大的对象会被删除)

				//FIFOLimitedCache //(根据先进先出的原则上删除多余对象)
				memoryCache(new FIFOLimitedMemoryCache(5 * 1024 * 1024));
		
		// 初始化imageLoader
		imageLoader.init(builder.build());

	}
5.在使用时
<pre name="code" class="java">ImageLoader.getInstance().displayImage(str_arr[position], viewHodler.imageView);


 第一个参数就是地址,第二个参数是imageView 

下边的不懂

// 加载图片时的属性,比如,加载失败显示的图片,是否把图片缓存的内存中.....
	DisplayImageOptions options = new DisplayImageOptions.Builder()
			// 图片路径为空的默认显示
			.showImageForEmptyUri(R.drawable.ic_launcher)
			// 图片的显示格式
			.bitmapConfig(Bitmap.Config.RGB_565)
			.showImageOnFail(R.drawable.icon_head)
			// 图片加载中,显示的默认图片
			.showImageOnLoading(R.drawable.bar1)
			.showImageForEmptyUri(R.drawable.icon_head).build();



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值