How do I display images in a facebook like feed? So far I've been using match_parent for width and wrap_content or fixed height. This works well but I need to show proper blank space for image feeds while it's getting lazy loaded. Like how do I set the dimensions properly for the image before loading it from the internet.
I think about getting the aspect ratio or the image dimensions itself via the api. Is it the only correct way or is there some other better way to achieve it using glide or any image loading library?
If you are using glide, you can set a place holder image or drawable with the dimensions you need while the real image is being downloaded.
Glide
.with(context)
.load(UsageExampleListViewAdapter.eatFoodyImages[0])
.placeholder(R.mipmap.ic_launcher) // can also be a drawable
.into(imageViewPlaceholder);
Related
I have an image that I'm trying to load with Picasso that I want to crop without scaling.
Is this possible?
For example, if I had:
an image that's 400x800
an image view that's 200x400
Any questions I've seen regarding cropping suggest using resize(x, y).centreCrop(alignGravity) (i.e. scaling and cropping rather than only cropping).
In the example, you'd get the entire image scaled to 50%, as the JavaDocs for centreCrop mentions:
This cropping technique scales the image so that it fills the requested bounds and then crops the extra, preferring the contents at alignGravity.
I want to display the middle 200x400 pixels of the image and lose the edges entirely (similar to how ImageMagick's crop would work).
Is there a way to crop without scaling?
So it seems that out-of-the-box, no it doesn't, but you can use the Picasso Transformations library to do so:
implementation 'jp.wasabeef:picasso-transformations:2.4.0'
and then:
Picasso.get()
.load(largeImage)
.transform(new CropTransformation(width, height, GravityVertical.CENTER, GravityVertical.CENTER))
.into(imageView, /* callback */);
If you are using resize() or centreCrop() you need to use after the call to transform().
When using a recycleView with many images, Glide takes a while to load the image for the first time, how can I preload the image's height and width by setting the imageView to that size before using glide to load it in?
Glide.with(mContext)
.load(link)
.apply(RequestOptions.centerInsideTransform())
.into(holder.vhImageView);
Reddit also does it this way
Glide may have an equivalent method, but I use Picasso, and you can set a .placeHolder(R.drawable.placeholder) image that will be in place until the image actually loads.
You could assign holder.vhImageView a default image in xml that should also work as a placeholder as long as Glide doesn't clear it as it's loading the new image?
You could set a minHeight on the holder.vhImageView in XML but that can cause problems if the views loaded end up being shorter than that.
I am currently using the Picasso to load the image file to image view on android. I tried to have an image resized then using fit to fit on the imageView. The fit cannot be used with resize.
Picasso.With().Load().Resize().Fit().Into()
Does the fit function will resize the image.
From the Document of Picasso
Attempt to resize the image to fit exactly into the target ImageView's
bounds. This will result in delayed execution of the request until the
ImageView has been laid out.
So i think the fit function will resize the image.
I'm trying to load an image from filesystem into an imageView with the ion library.
When I'm using the following code:
Ion.with(imageView)
.placeholder(R.drawable.placeholder_image)
.error(R.drawable.error_image)
.load(uri);
it (sometimes) results in a kind of blurry image.
When not using ion like the following the pictures appear sharply:
imageView.setImageBitmap(BitmapFactory.decodeFile(uri.toString()));
Is there a standard compression coming with ion that I can disable?
Strangely not every picture is blurry when using ion, e.g. I have two identical images, only with another name. When I load them into the imageView with ion one is blurry, one is not.
Any help or tips are appreciated!
Ion tries to load the image to fit the bounds of the ImageView. So make sure your ImageView is sized properly in your layout. Alternatively, if you use adjustViewBounds=true to indicate the ImageView is adjusted by the image contents, it won't do that. Or alternatively smartsize(false).
Try this,
Ion.with(context)
.load(url)
.withBitmap()
.placeholder(R.drawable.placeholder_image)
.error(R.drawable.error_image)
.intoImageView(imageView);
I load about images from about 30 different URLs into a ListView using Picasso. Some of the images are small, some of them are quite large (>3MB).
When I think of reducing the images using the Picasso method .resize(width, height) I dont know the original ration of the image I downloaded.
How could I possible know the dimensions of the downloaded (original) image in order to set the "new dimensions" or the resized image in the correct/appropriate relation?
Thanks