//ImageRequest请求图片
private void getImage() {
RequestQueue requestQueue = Volley.newRequestQueue(MainActivity.this);
//参数1:图片的网址,参数2:成功回调 参数3,4:图片的最大宽和高 参数5:设置图片样式,
ImageRequest imageRequest = new ImageRequest(ImageUrls.imageUrls[3], new Response.Listener() {
@Override
public void onResponse(Bitmap response) {
get_Image.setImageBitmap(response);
}
}, 0, 0, Bitmap.Config.RGB_565, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
requestQueue.add(imageRequest);
}
//ImageLoader
private void getImageLoader() {
RequestQueue requestQueue = Volley.newRequestQueue(MainActivity.this);
ImageLoader imageLoader = new ImageLoader(requestQueue, new ImageLoader.ImageCache() {
@Override
public Bitmap getBitmap(String url) {
Log.e("url", url);
return null;
}
@Override
public void putBitmap(String url, Bitmap bitmap) {
Log.e("putBitmap", url);
}
});
//设置请求回调 参数1:代表的是回调成功吧图片放到那个组件上,参数2:请求时加载的默认图片,参数3:请求失败的图片
ImageLoader.ImageListener imageListener = ImageLoader.getImageListener(get_Image, R.mipmap.iv_lol_icon3, R.mipmap.iv_lol_icon14);
imageLoader.get(ImageUrls.imageUrls[2] + "dsfsdf", imageListener);
}
网友评论