I was trying to fetch remote images which I've an API and display it in a Masonry Grid (Pinterest Style).
At first I was using simple GridView it was working perfectly but without the Masonry style. Then, after various research I was finally using:
Fresco
to fetch Image & CacheRecyclerView
withStaggeredGridLayoutManager
to display the images from the API.- Custom layout with
SimpleDraweeView
to display each item. - My own custom Adapter "MasonryAdapter" to bind the data to the view.
In the Custom layout, I set SimpleDraweeView with:
layout_with = match_parent
layout_height = wrap_content
Then, in my adapter I've set the correct aspect ratio to each of the image, as in my API I can get the images' width & height easily.
holder.contentImage.aspectRatio = image.width.toFloat() / image.height.toFloat()
Though at first moment everything looked acceptable but after scrolling I found everything breaks apart. I'm very new to Android
& Kotlin
, please ask if you need anything. Here I'm attaching a GIF to what is happening.
If image removed please check it here: https://ibb.co/dy0EjH