本篇博客将介绍一下xUtils的图片模块,想要学习的小伙伴请先看第一篇注解模块完成第一第二步哦。
Android快速开发框架之xUtils—注解模块:http://blog.csdn.net/a_zhon/article/details/52814534
Android快速开发框架之xUtils—网络模块:http://blog.csdn.net/a_zhon/article/details/52817530
1.在布局文件中添加了5个ImageView用来显示加载的图片,准备5个或多个图片地址
private String[] url = {
"http://images.juheapi.com/jztk/c1c2subject1/1.jpg",
"http://images.juheapi.com/jztk/c1c2subject1/25.jpg",
"http://images.juheapi.com/jztk/c1c2subject1/48.jpg",
"http://images.juheapi.com/jztk/c1c2subject1/131.jpg",
"http://images.juheapi.com/jztk/c1c2subject1/154.jpg"};
2.第一种加载方式
x.image().bind(imageView01, url[0])
3.第二种加载方式,为要加载的图片设置一些参数
ImageOptions options = new ImageOptions.Builder()
.setConfig(Bitmap.Config.RGB_565)//设置图片质量,这个是默认的
.setSquare(true)
.setCrop(true)//设置图片大小
.setSize(200, 200)//设置图片大小
.setFadeIn(true)//淡入效果
.setCircular(true)//展示为圆形
.build()
x.image().bind(imageView02, url[1], options)
4.ImageOptions 中所有的参数设置,仔细阅读哦
ImageOptions options = new ImageOptions.Builder()
.setConfig(Bitmap.Config.RGB_565)
.setFadeIn(true)
.setCrop(true)
.setSize(500, 500)
.setAnimation()
.setAutoRotate()
.setCircular(true)
.setFailureDrawable()
.setFailureDrawableId()
.setForceLoadingDrawable(true)
.setLoadingDrawable()
.setLoadingDrawableId()
.setIgnoreGif()
.setParamsBuilder(new ImageOptions.ParamsBuilder() {
@Override
public RequestParams buildParams(RequestParams params, ImageOptions options) {
params.addBodyParameter("key", "value");
return params;
}
})
.setPlaceholderScaleType()
.setRadius()
.setSquare(true)
.setUseMemCache()
.build();
5.第三种方式,带有回调监听函数
x.image().bind(imageView03, url[2], new Callback.CommonCallback() {
@Override
public void onSuccess(Drawable result) {
}
@Override
public void onError(Throwable ex, boolean isOnCallback) {
}
@Override
public void onCancelled(CancelledException cex) {
}
@Override
public void onFinished() {
}
});
6.第四种方式,传入四个参数的构造方法
x.image().bind(imageView04, url[3], options, new Callback.CommonCallback() {
@Override
public void onSuccess(Drawable result) {
}
7.第五种方式,使用x.image().loadDrawable()加载
x.image().loadDrawable(url[4], options, new Callback.CommonCallback() {
@Override
public void onSuccess(Drawable result) {
imageView05.setImageDrawable(result);
}
8.第六种方式,使用x.image().loadFile()加载
x.image().loadFile(url[5], options, new Callback.CacheCallback() {
@Override
public boolean onCache(File result) {
return true;
}
效果图
到这里就图片模块也说完了接下来就只剩下一个数据库模块了。
项目地址:https://github.com/azhong1011/xUtils