2017-04-10 56 views
1

我在mysql数据库中存储了我的图像的路径,并不确定是否有方法使用volley库在imageView中加载它们。使用volley库在ImageView中加载图像

我能够将字符串解析为json,并使用volley字符串请求队列将其显示在textView中,但不知道如何获取在imageView中显示为图像的路径。我想用id获取图像。

提前致谢!

回答

2

我总是用Glide加载这样的图像。就像你做任何其他字符串一样,返回路径。不需要使用Volley加载位图,使用Glide可以更简单,更好。 Glide将处理图像缓存和其他事情。

除了Volley部分,这是您所需要的全部。

ImageView imageView = findViewById(R.id.image); 
String url = "www.foobar.com/" + path; 
Glide.with(context).load(url).into(imageView); 
+0

这是非常有用的。感谢您向我展示这种方法! – Mkuuu7

0
new ImageRequest(
     url, 
     listener, 
     maxWidth, 
     maxHeight, 
     decodeConfig, 
     errorListener); 

Response.Listener<Bitmap> listener = new Response.Listener<Bitmap>() { 
    @Override 
    public void onResponse(Bitmap bitmap) { 
     //here you set the bitmap to imageview 
    } }; 
0

最近,我用毕加索库在我的项目和它的工作细腻。您可以使用Picasso轻松地将图像从Url加载到ImageView。此外,您可以调整原始图像的大小以适应您的尺寸。

例子:

String mURL = "https:\/\/c.tribune.com.pk\/2017\/12\/1593389-vanga-1514310781-708-160x120.jpg";  
ImageView Icon = (ImageView) findViewById(R.id.icon); 
Picasso.with(context).load(mURL).resize(72, 72).into(icon); 

注:使用毕加索首先你必须导入它的图书馆。

我用这个:compile'c​​om.squareup.picasso:picasso:2.5.2'