listview header with large image - android

I have a listview which headerView has a large image. When I call
listView.addHeaderView(headerView)
my listview doesn't scroll smoothly when I remove it it start scroll fine.
I am using Aquery lib for downloading image and cashing image
AQuery aq = new AQuery(img);
aq.id(R.id.image).image(mProduct.getMobile_pic(), true, true, mActivity.getCurrentDeviceDisplayMatrics().widthPixels, 0, new BitmapAjaxCallback(){
#Override
public void callback(String url, ImageView iv, Bitmap loadedImage, AjaxStatus status){
iv.setImageBitmap(loadedImage);
}
});
first true value is turn on memory cache, second is disk cache.
What possible reason could prevent smooth scroll of listview?

Related

How to use Glide's SimpleTarget with databinding?

I use Glide to load my image. I need to modify my image with a SimpleTarget callback, however when the image loaded to my list, and I scroll the list shows first always an other image, and than animate the right image after 1 second to the place. Without image modification and SimpleTarget everything works just fine. Here is my code.
#BindingAdapter("imageSrc")
public static void setImage(ImageView imageView, String url) {
Glide.with(imageView.getContext()).load(url).asBitmap().into(new SimpleTarget<Bitmap>() {
#Override
public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
//the bitmap modified here
imageView.setImageBitmap(bmp);
}
});
}
is there any solution to avoid the flickering?

Recyclerview NetworkImageView (volley) doesn't show up

I am using RecyclerView and volley's NetworkImageView to render images once they are downloaded. The view consists of an author image, some text fields and a picture. Following is the code snippet to populate the view:
// vh is the viewholder
vh.picture.setDefaultImageResId(R.drawable.default_image);
vh.picture.setImageUrl(post.getImageUrl(), mImageLoader);
The problem I am facing is when scrolling, out of say 20 images, mostly ~18 show up. I see from the logs that all images are downloaded and are in the cache, but some are not rendered. Even the default image is not displayed for those views. If the view is invalidated (scroll up and down again), the images show up.
Funny thing is, for the views where the picture is not displayed, even the author pic is not displayed, even if I can see the same author pic in a post just above it. Its as if the entire view has a problem displaying images.
Is there any way to call invalidate() or postInvalidate() on NetworkImageView manually once the images are downloaded? Or any other ideas?
This was also asked here. I finally got around to this problem by not using NetworkImageView at all. I started using the regualar ImageView, am still fetching the images through volley through a custom image request and onResponse() applying the image on the view. This seems to work pretty well.
public void getImage(String url, final ImageView v) {
if (TextUtils.isEmpty(url)) return; // don't fetch a null url
ImageRequest imageRequest = new ImageRequest(url, new Response.Listener<Bitmap>() {
#Override
public void onResponse(Bitmap response) {
v.setImageBitmap(response);
}
}, 0, 0, null, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Error- " + error.getMessage());
}
});
mRequestQueue.addToRequestQueue(imageRequest);
}

Universal Image Loader cache images

I have trouble finding the right workflow to load images into cache.
What I want to do:
Show Progress bar
Get data from REST service and load it into SQLite database
Some objects contain urls in JSON > load these images in cache so
they are quickly loaded when needed
Dismiss Progress bar
I have all the data loaded from rest and stored in a DB,
but I'm new to caching images.
What I go so far:
- Inserted Universal Image Loader into my project
(https://github.com/nostra13/Android-Universal-Image-Loader)
- I tried
imageLoader.loadImage(url of an image, new SimpleImageLoadingListener() {
#Override
public void onLoadingStarted(String imageUri, View view) {
super.onLoadingStarted(imageUri, view);
//notify me the image started loading
}
#Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
super.onLoadingComplete(imageUri, view, loadedImage);
//notify me the image is loaded
}
}
But when I check:
int size = MemoryCacheUtils.findCachedBitmapsForImageUri(url from that image, ImageLoader.getInstance().getMemoryCache()).size();
//show me the size
it's always zero.
My question is the following: am I going in the right direction or do I need to fix this someother way?
I found a better solution: ShutterBug (Android alternative for SDWebImage for iOs). It's easy to add urls to the ShutterbugManager and when I want to fill an ImageView (FetchableImageView in Shutterbug) with an image, it grabs the image from cache.

Unable to set image view background image using universal image loader?

I am trying to set background for the image view. But not got luck to set background using universal image loader.
I am using following code.
DisplayImageOptions options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.mo_no_image)
.showImageForEmptyUri(R.drawable.mo_no_image)
.cacheInMemory().cacheOnDisc()
.displayer(new RoundedBitmapDisplayer(0))
.imageScaleType(ImageScaleType.EXACTLY).build();
ImageLoader.getInstance().displayImage("url_to_load_image", imgView, options);
By using above code I am able to set image resource which check aspect ratio and using that modifying image size.
I want to set downloaded image to the background of image view.
I can recommend a different way that works like a charm: Android Query.
You can download that jar file from http://code.google.com/p/android-query/downloads/list
AQuery androidAQuery=new AQuery(this);
As an example:
androidAQuery.id(YOUR IMAGEVIEW).image(YOUR IMAGE TO LOAD, true, true, getDeviceWidth(), ANY DEFAULT IMAGE YOU WANT TO SHOW);
It's very fast and accurate, and using this you can find many more features like Animation when loading; getting a bitmap, if needed; etc.
In your case you need to fetch Bitmap, so for it, use below code
androidAQuery.ajax(YOUR IMAGE URL,Bitmap.class,0,new AjaxCallback<Bitmap>(){
#Override
public void callback(String url, Bitmap object, AjaxStatus status) {
super.callback(url, object, status);
//You will get Bitmap from object.
}
});
Use this bitmap to set your background resource of ImageView using method.
Universal Image Loader also provide to use the Background functionality.Please check the below coed for it:-
Here Uri is the path of the folder image OR the url of the image.
imageLoader.loadImage(YOUR_URL, new SimpleImageLoadingListener() {
#Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
super.onLoadingComplete(imageUri, view, loadedImage);
layout.setBackgroundDrawable(new BitmapDrawable(loadedImage));
}
});

How to load multiple image of specified size?

I want to load multiple image(list view or gridview) of specified size (i need to change height and width of image at run time) .Can anyone suggest me for any library which support this functionality ?
imageloader.loadimage(imageview,"imageurl",height,width);
Check out UniversalImageLoader. I think this is the best library for loading images. In its loading listener you can resize the loaded image before display it.
Try by this one : and check this for refrence https://github.com/nostra13/Android-Universal-Image-Loader
ImageSize targetSize = new ImageSize(120, 80); // result Bitmap will be fit to this size
imageLoader.loadImage(imageUri, targetSize, displayOptions, new SimpleImageLoadingListener() {
#Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
// Do whatever you want with Bitmap
}
});

Categories

Resources