In my android application, I am using universal image loader to show images from url. During loading of image I want a gif image to be shown. But the gif image added is not showing any animation.
Here is my code to display image.
private static final DisplayImageOptions.Builder DEFAULT_DISPLAY_IMAGE_OPTIONS_BUIDLER = new DisplayImageOptions.Builder()
.imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2)
.displayer(new FadeInBitmapDisplayer(300, true, false, false))
.showImageForEmptyUri(R.drawable.default_image)
.showImageOnLoading(R.drawable.loadingx)
.showImageOnFail(sampleapp.sample.com.sampleapp.R.drawable.default_image).cacheOnDisk(true)
.cacheInMemory(true).bitmapConfig(Config.ARGB_8888);
what changes should I make to show an animated gif image during loading time image
Try to use glide for gif image loading...
Glide
.with( context )
.load( gifUrl )
.asGif()
.error( R.drawable.full_cake )
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.into( imageViewGif );
To understand follow the link -
here
If you want to use ProgressBar then create a method like below -
public void loadImage(Context context, String url, ImageView img, final ProgressBar eProgressBar) {
eProgressBar.setVisibility(View.VISIBLE);
Glide.with(context)
.load(url)
.listener(new RequestListener<String, GlideDrawable>() {
#Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
eProgressBar.setVisibility(View.GONE);
return false;
}
#Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
eProgressBar.setVisibility(View.GONE);
return false;
}
})
.crossFade()
.error(R.drawable.placeholder_image)
.into(img);
}
Use this method and pass your parameter value through it... :)
Universal Image Loader doesnot Support Gif see this Try using other libraries like Glide which supports gif
Glide.with(context)
.load(imageUrl)
.asGif()
.placeholder(R.drawable.yourgif)
.crossFade()
.into(imageView);
I got answer by using glide library. But glide is slower than universal image loader.
Glide.with(getActivity().getApplication())
.load(item.imageUrl)
.thumbnail(Glide.with(getActivity().getApplication()).load(R.drawable.loadingx))
.fitCenter()
.crossFade()
.into(holder.image);
Related
I want fitXY scaleType for image and fitCenter for place holder. I am fetching data from api using volley and loading image using glide.
How am I supposed to know that image is null ?
XML and code
<ImageView
android:id="#+id/NewsImage"
android:layout_width="120dp"
android:layout_height="120dp"
android:scaleType="fitCenter" />
Glide.with(context).load(news.getUrlToImage()).placeholder(R.drawable.place_holder).dontAnimate().into(holder.NewsImage);
1.USING LISTENER
Using GLIDE you can add a listener for image loading. Once the image is loaded change the SCALE type of the ImageView.
Glide.with(getActivity())
.load(args.getString(IMAGE_TO_SHOW))
.listener(new RequestListener<String, GlideDrawable>() {
#Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
return false;
}
#Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
imgview.setScaleType(ImageView.ScaleType.FIT_XY);
return false;
}
})
.into(imgview)
2.USING GLIDE
You can use one of the GLIDE transformations for the image or create your custom transformation
https://github.com/bumptech/glide/wiki/Transformations
You can use Best Image Loading Library Picasso for this.
If their is no image it will show place holders image into imageview
Picasso.get()
.load("http://i.imgur.com/DvpvklR.png") //loading url image
.placeholder(R.drawable.custom_image) // during loading this image will be set imageview
.error(R.drawable.error) //if image is failed to load - this image is set to imageview
.networkPolicy(NetworkPolicy.OFFLINE) //stores images for offline view
.resize(50, 50) //resize
.centerCrop() // apply scaling OR
.fit() //apply scaling OR
.centerInside() //scaling
.into(imageView, new Callback() {
#Override
public void onSuccess() {
//called when image is loaded successfully.. \n \n
}
#Override
public void onError(Exception e) {
//called when image is failed to be loaded into.
}
});
I use glide in fragment using recycler view but images are not showing properly.
please suggest me to slove this issue
Glide.with(context)
.load( image_url)
.placeholder(R.drawable.pic)
.error(R.drawable.pic)
.fitCenter()
.into(Viewholder.imageView);
By default Glide uses low resolution images to save data and improve performance.
boolean isHighResolution = true;
BitmapRequestBuilder<String, Bitmap> builder = Glide
.with(this)
.load(url)
.asBitmap()
.format(isHighResolution
? DecodeFormat.PREFER_ARGB_8888
: DecodeFormat.PREFER_RGB_565)
builder.into(imageView);
You can try this code, and see if this helps.
The image to be loaded size should be greater and doesn't loaded properly and it is blurred.
use Bitmap and compress the image like below
Glide.with(mContext)
.load(album.getBannerUrl())
.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(new SimpleTarget<Bitmap>() {
#Override
public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
// Do something with bitmap here.
holder3.headerimage.setImageBitmap(bitmap);
Glide.with(mContext)
.load(album.getBannerUrl().get(0))
.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(new SimpleTarget<Bitmap>() {
#Override
public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
// Do something with bitmap here.
holder3.headerimage.setImageBitmap(bitmap);
}
});
}
});
The images I load with Picasso seem to use a density value of DENSITY_NONE. What do I have to change to make Picasso call .setDensity(160) on the loaded images before they are displayed?
Basing myself on another Picasso solution to resize images I implemented a custom transformation object which sets the density of images to a constant of my own:
Transformation changeDensity = new Transformation()
{
#Override public Bitmap transform(Bitmap source)
{
source.setDensity(160);
return source;
}
#Override public String key()
{
return "density";
}
};
// …later…
Picasso
.with(context)
.load(imageUri)
.transform(changeDensity)
.into(imageView);
I am using Glide library for loading images in imageview and using the below code.
Glide.with(mActivity)
.load(img.getmGridViewImageUrl())
.placeholder(R.color.grey_light)
.into(imageHolder.imageView);
The placeholder with grey color gets visible until the image does not load but after the image get loads in imageview, the placeholder still take place and show some blank space after that image.
How can I resolve this issue. Please help me if you have any idea here.
Try this code.
When I give fix height to the ImageView it works for me.
Here's the layout
<ImageView
android:id="#+id/imgPoster"
android:layout_width="fill_parent"
android:layout_height="#dimen/height_of_getInspired_list"
android:layout_centerVertical="true"
android:scaleType="fitXY"
android:src="#drawable/default_image"/>
Here's my code.
Glide.with(this.context).load(inspiredList.get(position).image)
.error(R.drawable.default_image)
.centerCrop()
.crossFade()
.placeholder(R.drawable.default_image).into(holder.imgPoster);
Try this code.. This will help you..
Glide.with(this).load(photo_url)
.crossFade()
.thumbnail(0.5f)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.plaeholder_image)
.listener(new RequestListener<String, GlideDrawable>() {
#Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
return false;
}
#Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
imageView.setImageDrawable(resource);
return false;
}
})
.into(imageView);
Please use placeholder image instead of color. you will able to use plain grey color image from drawable for placeholder image.
I'm using picasso library for loading images from server into my application. my problem is when image loaded it has a triangle in top-left corner of image with color(like blue,green,red).
this is my code for loading image:
public static void loadDynamicImage(final String url, final Context context, final ImageView imageView, final int width, final int height){
Picasso.with(context).load(url)
.networkPolicy(NetworkPolicy.OFFLINE)
.resize(width,height)
.onlyScaleDown()
.into(imageView, new Callback() {
#Override
public void onSuccess() {
}
#Override
public void onError() {
Picasso.with(context).load(url).resize(width,height).onlyScaleDown().into(imageView);
}
});
}
the image shown is :
You have enabled debug indicators on your Picasso instance (see official website). Look for setIndicatorsEnabled(true) in your code and remove it.
You have setIndicatorsEnabled set to true
Picasso picasso = Picasso.with(this);
picasso.setIndicatorsEnabled(false); //Or remove picasso.setIndicatorsEnabled(true);
Check this: Is there any way from which we can detect images are loading from cache in picasso?