Set up recyclerView height when loading items asynchronously

Viewed 172

I have a recyclerView

<androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

and I load items asynchronously using AsyncLayoutInflater as explained in this answer The problem is that my recyclerview has wrap_content height and it's not aware of items height before they are loaded and it takes arbitrary height sometimes. I tried to hardcode item height but it's not a good solution. I can also try to calculate the hight of the view in runtime but I'm afraid I'll lose in performance and async loading will be useless. Is there a better way to let recyclerView what height should it be when all the items are loaded?

0 Answers
Related