RecyclerView Content Height

Is there a good way to get the height of the content inside the RecyclerView? Given that all items can have different heights.

In my script, I am using LinearLayoutManager.

I searched around and found surprisingly few results for this problem.

+7
android height android-recyclerview
source share
2 answers

RecyclerView is a ViewGroup . You can use getChildAt / getChildCount to get views. Then from the view, you can call getWidth / getHeight .

If you have ItemDecorators and need to get the size, including them, you can use the LayoutManager getDecorated<xxx> methods.

+12
source share

RecyclerView.computeVerticalScrollRange will give an estimate - it averages the height of the rows currently being displayed and multiplies them by the result of getItemCount

computeHorizontalScrollRange for width if the orientation is horizontal.

+19
source share

All Articles