RecyclerView with StaggeredGridLayoutManager with images loading from Glide

Passiondroid picture Passiondroid · Mar 22, 2016 · Viewed 8k times · Source

I am having a problem showing RecyclerView with StaggeredGridLayoutManager whose item contain an imageview and the image is loaded in imageview using glide. The problem i am facing is that after images getting loaded they are not staggered and are of equal sizes as well there is a big gap between two columns. How to vary the height of images with no gaps in columns?

Answer

Don Shrout picture Don Shrout · Dec 24, 2016

I was having the same issue. What worked for me was to set android:adjustViewBounds="true" for my ImageView. I'm not even setting scaleType.

Here's the full content of my layout file, item.xml.

<?xml version="1.0" encoding="utf-8"?>
<ImageView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/gif_image"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorFiller"
    android:adjustViewBounds="true"/>

Hope this helps!