我在mysql數據庫中存儲了我的圖像的路徑,並不確定是否有方法使用volley庫在imageView中加載它們。使用volley庫在ImageView中加載圖像
我能夠將字符串解析爲json,並使用volley字符串請求隊列將其顯示在textView中,但不知道如何獲取在imageView中顯示爲圖像的路徑。我想用id獲取圖像。
提前致謝!
我在mysql數據庫中存儲了我的圖像的路徑,並不確定是否有方法使用volley庫在imageView中加載它們。使用volley庫在ImageView中加載圖像
我能夠將字符串解析爲json,並使用volley字符串請求隊列將其顯示在textView中,但不知道如何獲取在imageView中顯示爲圖像的路徑。我想用id獲取圖像。
提前致謝!
我總是用Glide加載這樣的圖像。就像你做任何其他字符串一樣,返回路徑。不需要使用Volley加載位圖,使用Glide可以更簡單,更好。 Glide將處理圖像緩存和其他事情。
除了Volley部分,這是您所需要的全部。
ImageView imageView = findViewById(R.id.image);
String url = "www.foobar.com/" + path;
Glide.with(context).load(url).into(imageView);
您可以按照本教程來使用Volley庫顯示圖像,這並不複雜。
我希望這可以幫助你。
https://www.simplifiedcoding.net/android-volley-example-to-load-image-from-internet/
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
} };
最近,我用畢加索庫在我的項目和它的工作細膩。您可以使用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'com.squareup.picasso:picasso:2.5.2'
這是非常有用的。感謝您向我展示這種方法! – Mkuuu7