I am working on an application which uses Google Firebase and RecyclerView. While retrieving the images from Firebease, images are not properly scaling up. When scrolling the recyclerview, sometimes images are showing as smaller ones and sometimes bigger. They are not scalling properly. I am using Glide to load the images. Please help me .
Also, is it a good idea to use Recuyclerview to use in complex application since OnbindViewHolder being called multiple times causing performance issues. Is there any alternative for that.
Please use this code:
Glide.with(profilePhotoImageView.getContext())
.load(profilePhotoUrl).centerCrop()
.transform(new CircleTransform(profilePhotoImageView.getContext()))
.override(40,40)
.into(profilePhotoImageView);
This means that you are setting a fixed width and height. In which profilePhotoUrl is the url of your image and profilePhotoImageView is the ImageView in which you want to display the image.
And don't forget to add the latest version of Glide in your build.gradle file.
'com.github.bumptech.glide:glide:4.0.0-RC1'
Hope it helps.
Related
I am using Picasso to show images from url. My issue is , when I used debug APK, all images in list and grid view show perfect, whenever I upload APK to play store and install Live app, some of image stretch height wise. I did not give width and height in layout. I am not able to figure out the issue. Please help.
Debug App
Live app
Screenshot from both app is added.
Try this Glide This is perfect for Url Image.
Add this library to your gradle file
implementation 'com.github.bumptech.glide:glide:4.11.0'
Glide.with(OurAppsActivity.this)
.load(image_url)
.into(your_ImageView);
Perhaps what you need is making images have fixed aspect ratio on all phones.
Customize ImageView: https://github.com/santalu/aspect-ratio-imageview/
Use ConstraintLayout: ConstraintLayout aspect ratio
I implemented a RecyclerView in one of my Activities.
I use a customized RecyclerView adapter to load data from a SQLite Database (using Room and LiveData-structure) and display it in the view.
All of the rows have a large ImageView where I want to show a Drawable (just a .png). To do that I first tried to use the approach written on the official Android Developers site but it did not work well for me.
Therefore I am trying to use Glide as a library recommended by Google.
I have 16 drawables in my project. They all have a scaling between 800x800 and 1920x1080 pixels.
In my adapter I load the data from my database and based on the drawable id, the image as well (so there is no image data stored in the database; I did this previously).
Unfortunately my App cannot handle that amount of image cache which leads to an OutOfMemoryError exception. That's why I used
android:largeHeap = "true"
in my Android Manifest.
I know this is not a good solution and I also know that there has to be a way to use less memory for such a small amount of pictures.
In Glide I use
GlideApp
.load(R.drawable.my_drawable)
.fitcenter()
.into(myImageView);
But unfortunately the image does not get shrinked or smaller. I thought that Glide can scale the image based on the size of the ImageView, screen size and so on.
What am I doing wrong? Is there a better way to use less memory without fixed scaling so that my pictures not become ugly?
EDIT:
I first stored my images in the basic "drawable" folder in my project structure (copy and paste).
My second approach was the gimp-android-xdpi addon which exports images or icons for any android density (mdpi, hdpi, xhdpi etc.). But this did not help either.
call override(horizontalSize, verticalSize).
This will resize the image before displaying it in the ImageView.
I've been trying to create a Recycler View full of Card Views. Currently, I'm using the Recycler View from this tutorial and loading it with 14 different images. The professional quality images range in size from 134K to 242K.(Down from 8MB - 18MB)
I know that the images may be too big but, I feel there must be some way to get better performance while scrolling. Can someone point me in the right direction?
Edit: The images will be stored on the device. There will probably never be more than 20 of them.
You can use Picasso library or Android Universal Image Loader
Picasso
Android-Universal-Image-Loader
You don't need any AsyncTask.Theese 2 library handling image operations in background so you can keep scrolling smoothly. I am using Picasso in my project right now. You can add error drawable , temporary placeholder default drawable , and its so simple automatically caching.
Just use one of them in onBindViewHolder to bind any image to imageView
Load the images in a separate thread (or AsyncTask).
Assumes I have a picture, it very large images or other sets of content where you are only looking at small bits at a time, because you can start seeing your content without having to load it all into memory at once.
In iOs we can use CATiledLayer to repeatedly draw tiles to fill up view’s background
In Android I can see Google Map, It also load each part of map when you scroll but I don't understand what is solution of them.
I want know what is the solution same CATiledLayer in Android or other to load very large Image
you can actually scale down the bitmap according to the size of the image view.
Don't give wrap_content in width and height try to give a relative width and height.
use
ImageView.getheight()
ImageView.getWidth()
get the size and load according to it
see this link
http://developer.android.com/training/displaying-bitmaps/load-bitmap.html#read-bitmap
You can use a library load images efficiently and manage caching them instead of downloading them again. I suggest Picasso or Glide. This tutorial compares between them and explains few features.
I hope it's useful.
I am using the Scrollable ImageView by Egor Andreevich found here.
Although I have successfully managed to insert this into my app, the issue I'm having is that my image is very laggy. The image I'm using is 1.63 mb and 3713x3329 in dimension. If I use a smaller image that is both small in dimension and size, then it works perfectly.
The post you are referring to seems to be an introduction of scrolling images in an ImageView, and not a complete implementation. I would direct you to PhotoView for a more complete implementation.