问题
Hi i am new beginner in android. I want to insert image in imageView from URL but whenever one time it is loaded from URL in imageView then second time it should be insert without internet means it would be stored in cache as well.
回答1:
for this you can use picasso Library You can download it from Picasso Library site simply put this jar file into libs folder. It will manage all property of Image. http://square.github.io/picasso/
String imgURL = "Your URL";
ivmage = (ImageView) findViewById(R.id.imageView1);
Picasso.with(MainActivity.this).load(imgURL).into(ivmage);
回答2:
You can use Picasso
Library.
By Using Picasso
, The Advantages are
- Handling ImageView recycling and download cancelation in an adapter.
- Complex image transformations with minimal memory use.
- Automatic memory and disk caching.
To load Image
from Url
Picasso.with(context).load(url).into(imageView);
Refer this link for Api : Picasso
回答3:
you can use Glide https://github.com/bumptech/glide
Glide.with(this).load("imageURl").into(imageView);
回答4:
I suggest picasso library for doing this. here is the detailed documentation of picasso library.
ex:
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);
or you can make use of volley's ImageLoader. here you can find the documentation for Volley's image loading.
ex :
// Retrieves an image specified by the URL, displays it in the UI.
ImageRequest request = new ImageRequest(url,
new Response.Listener<Bitmap>() {
@Override
public void onResponse(Bitmap bitmap) {
mImageView.setImageBitmap(bitmap);
}
}, 0, 0, null,
new Response.ErrorListener() {
public void onErrorResponse(VolleyError error) {
mImageView.setImageResource(R.drawable.image_load_error);
}
});
// Access the RequestQueue through your singleton class.
MySingleton.getInstance(this).addToRequestQueue(request);
if you are using volley. then you have to cache images manually. picasso will cache images by default.
来源:https://stackoverflow.com/questions/32941372/load-image-from-url-to-imageview-as-well-as-cache