使用齐射库在ImageView中加载图像

问题描述 投票:1回答:4

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

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

提前致谢!

android android-volley
4个回答
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);

1
投票

最近,我在我的项目中使用了Picasso库,它工作得非常顺畅。您可以使用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);

注意:首先使用Picasso,您必须导入其库。

我用过这个:编译'com.squareup.picasso:picasso:2.5.2'


0
投票

使用glide来显示你的图像,或者你可以使用picasso


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
    } };
© www.soinside.com 2019 - 2024. All rights reserved.