Views in RecyclerView still has height of 0 even when displayed

Views in RecyclerView still has height of 0 even when displayed

0

0



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
               itemView.viewTreeObserver.removeOnGlobalLayoutListener(this)
           }


java android kotlin

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Top Android Projects with Source Code

Android projects with source code - Work on real-time android projects. We’ll start project ideas from beginners level and later move to advance projects.

How to Install OpenJDK 11 on CentOS 8

What is OpenJDK? OpenJDk or Open Java Development Kit is a free, open-source framework of the Java Platform, Standard Edition (or Java SE).

Kotlin vs Java | Kotlin or Java For Android Development | Kotlin And Java Difference

Kotlin and Java have showcased the cut-throat competition in the lastest Android Development. There are a lot of ambiguities amongst developers to choose one, from both. This video will help you to understand the strengths and weaknesses of both with a head to head comparison.

Java vs Kotlin for Android Development — 16 Pros and Cons

The technical difference is significant, but if you plan on doing Android development, learn both. Most of the popular libraries are backward compatible with Kotlin, Java code can be used in Kotlin and vice versa, but to solve a problem or simply understand all the nuances of the documentation, you should know Java. Having mastered both programming languages, you will become a sought-after specialist and secure a good future for yourself in developing applications for Android.

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!