Views in RecyclerView still has height of 0 even when displayed

Views in RecyclerView still has height of 0 even when displayed



I am confused because in my RecyclerView, some items has their height = 0 (even when they are correctly displayed and visible) and some have their normal height.

How is that possible ? If I monitor the height with addOnGlobalLayoutListener, 90% of item has their correct height calculated, and 10% still have 0. Any idea of how android works for this ?

My code is in Kotlin but it doesn’t matter.

init {
       var heightItemView = 0
       var currentY = itemView.y
       var oldY = currentY

   itemView.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
       override fun onGlobalLayout() {
           if (itemView.measuredHeight > 0) {
               heightItemView = itemView.measuredHeight

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Kotlin Coroutines on Android - How to use Coroutines on Android

Coroutines are a Kotlin feature that convert async callbacks for long-running tasks, such as database or network access, into sequential code. This Kotlin Coroutines tutorial will show you how to use coroutines on Android, and how the new androidx-concurrent library makes it easy to use them to get things off the main thread. You'll also learn how the new library helps coroutines work with Architecture Components. This session also covers coroutine patterns, best practices, and even how to test coroutines!

What's New in Java 19: The end of Kotlin?

What's New in Java 19: The end of Kotlin? Will Kotlin still have a place in the JVM language ecosystem in a few years? This tutorial will compare and contrast how the two languages approach solving the same problems of today's Java. We'll peer a few years into the future to see where both languages are headed and determine whether we still need a Kotlin

Kotlin vs Java: Which is the best for Android Developers?

In this article will help you spot the major differences between Kotlin vs Java