xUtils3 图片加载模块

xUtils3 图片加载模块
xUtils3 提供的主要方法如下:

x.image().bind(imageView, url, imageOptions);

// assets file x.image().bind(imageView, "assets://test.gif", imageOptions);

// local file x.image().bind(imageView, new File("/sdcard/test.gif").toURI().toString(), imageOptions);

x.image().bind(imageView, "/sdcard/test.gif", imageOptions);

x.image().bind(imageView, "file:///sdcard/test.gif", imageOptions);

x.image().bind(imageView, "file:/sdcard/test.gif", imageOptions);

x.image().bind(imageView, url, imageOptions, new Callback.CommonCallback<Drawable>() {...});

x.image().loadDrawable(url, imageOptions, new Callback.CommonCallback<Drawable>() {...}); x.image().loadFile(url, imageOptions, new Callback.CommonCallback<File>() {...});

可以加载网络图片,加载 sdcard 里面的图片,可以加载当前工程 assets 目录的 图片。

1_使用 xUtils3 加载单张图片
使用 xUtils3 加载图片的时候,要设置一些配置,如果内存不足,可以设置图片的宽和高小 一些

private void getImage() {

        imageOptions = new ImageOptions.Builder().setSize(DensityUtil.dip2px(80), DensityUtil.dip2px(80))
                .setRadius(DensityUtil.dip2px(5))
                .setImageScaleType(ImageView.ScaleType.CENTER_CROP)
                .setLoadingDrawableId(R.mipmap.ic_launcher)
                .setFailureDrawableId(R.mipmap.ic_launcher).build();
        x.image().bind(iv_icon, "http://img31.mtime.cn/mg/2016/09/02/113643.5194 1003.jpg", imageOptions);
    }

2_使用 xUtils3 加载 gif 图片
设置加载 gif 图片一定要设置 setIgnoreGif(false)为 false,还可以加载本地的 gif 图 片。 

 private void getImage() {

        imageOptions = new ImageOptions.Builder().setSize(DensityUtil.dip2px(80), DensityUtil.dip2px(80))
                .setRadius(DensityUtil.dip2px(5)).setIgnoreGif(false)
                .setImageScaleType(ImageView.ScaleType.CENTER_CROP)
                .setLoadingDrawableId(R.mipmap.ic_launcher)
                .setFailureDrawableId(R.mipmap.ic_launcher).build();
        x.image().bind(iv_icon, "http://image82.360doc.com/DownloadImg/2015/02/1 621/50253472_10.gif", imageOptions); /
    }
        

3_使用 xUtils3 在列表中加载图片
在列表中加载图片,和加载单张图片类似,也要配置一下即可。 主要是在适配器的 getView 中加载图片 。

猜你喜欢

转载自www.cnblogs.com/yanglanwan/p/11305574.html