use xml file in simpleimageview setplaceholderimage - android

Is there any way to use xml layout into fresco library instead of hierarchy image?
I used layout like below :
simpledraweeview.getHierarchy().setPlaceholderImage(layout.id);
but it didn't work.
this error hapend :
.Resources$NotFoundException: File res/layout/hierarchy_layout.xml from drawable resource ID #0x7f040049

It means the resource what you are trying to apply is not available. My Suggestion is you can try Picasso library.
Picasso.with(context)
.load(url)
.placeholder(R.drawable.user_placeholder)
.error(R.drawable.user_placeholder_error)
.into(imageView);
or
you can try Glide library.
Glide.with(myFragment)
.load(url)
.centerCrop()
.placeholder(R.drawable.loading_spinner)
.crossFade()
.into(myImageView);

Fresco supports setting your placeholder in XML: http://frescolib.org/docs/using-drawees-xml.html#_

Related

Glide - Round image without circle crop

I'm using this code to show profile image:
Glide.with(getContext()).load(url)
.dontAnimate()
.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
.circleCrop()
.into(my_profile_image);
But circleCrop() is cropping the image too much. So is there another way to round an image without too much cropping? I research it but I couldn't find another method.
Glide.with(getContext()).load(url)
.dontAnimate()
.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
.apply(RequestOptions.bitmapTransform(new RoundedCorners(10))) // round
.into(my_profile_image);
How about this?
Glide.with(getContext()).load(url)
.dontAnimate()
.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
.apply(RequestOptions.circleCropTransform())
.into(my_profile_image);

Image not properly loaded in PolygonImageView using Glide

I am trying to load the image in polygon ImageView using glide library here is the code
GlideApp.with(Activity.this)
.load(path)
.placeholder(R.drawable.user_avatar)
.into(polygonImageView);
When i using this code result is in below image (the image is cut from right and bottom)
But i want this as result
For Polygon ImageView using third party library Click Here to Check Library
Any Help from you will be appreciated.Thanks
I am Refered That PolyGon Imageview Library But Issue was not There.
Just Use This Code It ll be Works Like a Charm
RequestOptions options = new RequestOptions();
options.centerCrop();
Glide.with(this)
.load("your URL")
.apply(options)
.into((ImageView) findViewById(R.id.imageview));

Picasso - how to resize placeholder

I'm using a 128x128 circular image, animated by a drawable as a placeholder in Picasso.
<?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/loading_circle"
android:pivotX="50%"
android:pivotY="50%" />
And this is how my Java code implements it:
Picasso.with(context)
.load(message.getMediaUrl())
.config(Bitmap.Config.ARGB_4444)
.resize(w, h)
.onlyScaleDown()
.centerCrop()
.placeholder(R.drawable.progresscircle)
.into(messageImage);
Note that the image sizing parameters above are required by the final image that is loaded into my chat adapter's imageview.
The problem is, Picasso is blowing up and cropping the placeholder like this:
How can I set separate parameters for the placeholder to be suitably sized? Also, what exact parameters would be helpful?
in XML where you set ImageView add.
android:scaleType="centerCrop"
It may work. you can set fitXY instead of centerCrop if it is not working.
As mentioned here,
Inside your imageviews xml set android:scaleType="centerInside"
Then add fit().centerCrop().noFade() like this
Picasso.with(context)
.load(message.getMediaUrl())
.config(Bitmap.Config.ARGB_4444)
.resize(w, h)
.onlyScaleDown()
.centerCrop()
.fit()
.noFade()
.placeholder(R.drawable.progresscircle)
.into(messageImage);
Try this:
Picasso
.with(context)
.load(message.getMediaUrl())
.fit()
// call .centerInside() or .centerCrop() to avoid a stretched image
.into(messageImage);
change your Picasso call to this,
Picasso.with(context)
.load(message.getMediaUrl())
.config(Bitmap.Config.ARGB_4444)
.fit()
.centerCrop()
.placeholder(R.drawable.progresscircle)
.into(messageImage);

How to load GIF image from drawable folder into ImageView using glide?

I have to show load GIF image from drawable to ImageView using glide.I have tried with following.
Glide.with(LoginActivity.this)
.load(getResources().getDrawable(R.drawable.bg_gif)).asGif()
.crossFade()
.into(relativeLayout);
But isn't seem working and it's working when I'm place image in raw folder.but the problem is I have to use different dimension images.
Any help would be greatly appreciated.
You can try to use Ion it works fine for me.
Ion
Using Ion
Ion.with(imgView)
.error(R.drawable.default_image)
.animateGif(AnimateGifMode.ANIMATE)
.load("file:///android_asset/animated.gif");
Using Glide
ImageView imageView = (ImageView) findViewById(R.id.imageView);
GlideDrawableImageViewTarget imageViewTarget = new GlideDrawableImageViewTarget(imageView);
Glide.with(this).load(R.raw.sample_gif).into(imageViewTarget);
Another Approach
For Glide 3.0 you need to set asGif() earlier:
Glide.with(context)
.load(imageUrl)
.asGif()
.placeholder(R.drawable.loading2)
.crossFade()
.into(imageView);
Keep in mind that just using load() will load either a GIF or a Bitmap depending on the type of the data. Unless you want your load to fail if the given url is not a gif, you don't need to specify asGif()
Just pass the resource id directly to load():
Glide.with(LoginActivity.this)
.load(R.drawable.bg_gif)
.asGif() // you may not need this
.crossFade()
.into(relativeLayout);
Steps to load Gif images from drawable
You need to move your Gif image tores/raw folder of your project
(
if your project don't have raw folder in resource directly then simply make one and put your gif in it )
and then you can simply load your gif with just one line of code
Glide.with(this)
.load(R.raw.splash)
.into(new GlideDrawableImageViewTarget(
(ImageView) findViewById(R.id.image)));
Place your Gif in the "raw" folder and use
GlideDrawableImageViewTarget imageViewTarget = new GlideDrawableImageViewTarget(imageView);
Glide.with(this).load(R.raw.test).into(imageViewTarget);
For Glide 4
GlideApp.with(this)
.load(R.raw.gif_file)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.into(imageView);

Picasso center image without resizing into ImageView

I've come across this simple problem with the Picasso library. I haven't find any way to put an image into ImageView center it like android:ScaleType="center" does without cropping. Do you have any ideas about how to solve this ? My problem is that I don't know at the runtime the height and width of the BitMap I download so I can't use resize() properly.
This is a little late, but for anyone who's looking for a solution :
Picasso
.with(context)
.load(ImageURL)
.fit()
// call .centerInside() or .centerCrop() to avoid a stretched image
.into(imageViewFit);
If your ImageView is fixed one dimension and flexible another dimension (ex. android:width="match_parent", android:height="wrap_content"), you should be able to use android:adjustViewBounds="true" to get the ImageView to resize to display your image without cropping.
i am not found fit to center without resizing,
Picasso.get()
.load(source).resize(1650,700)
.centerCrop(Gravity.CENTER).into(imageView, new Callback()

Categories

Resources