这节我们来看Request的另一个子类ImageReqeust,这个类是用来请求图像资源的。先看看使用方法。(图片实际尺寸1920*1080)
构造函数:
public ImageRequest(String url, Listener<Bitmap> listener, int maxWidth, int maxHeight, ScaleType scaleType, Config decodeConfig, ErrorListener errorListener) {
super(0, url, errorListener);
this.setRetryPolicy(new DefaultRetryPolicy(1000, 2, 2.0F));
this.mListener = listener;
this.mDecodeConfig = decodeConfig;
this.mMaxWidth = maxWidth;
this.mMaxHeight = maxHeight;
this.mScaleType = scaleType;
}
我们看到,ImageRequest的构造函数中需要传入宽度,高度(宽高可以传入0),缩放类型,选项等信息,并且重新设置了DefaultRetryPolicy重试策略。
因为图片的请求往往比较耗时,所以Volley把它的优先级设置为低级。
public Priority getPriority() {
return Priority.LOW;
}
使用代码如下,设置最大宽和高为600和400,居中,其它参数不传: