RecyclerView horizontal linearlayout manager is causing recyclerview not showing

50 Views Asked by At

at first my code goes

<androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rvPrices"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
        app:layout_constraintTop_toTopOf="parent"
        tools:itemCount="3"
        tools:listitem="@layout/business_item_fire_job_price_des" />

setting layout manager in recycler view xml

The problem is that when items added to adapter, I can see the log that it has called the bindData, but on some occasions the recyclerview is gone, can anybody explain why?

seems that the problem happens when the UI refreshing was a little bit lagging(in android studio miror devices the problems happens more ofen)

I tryied to change the layoutmanager to vertical and it works fine, but i want the recyclerview to layout horizontally

1

There are 1 best solutions below

0
el magnifico On

I now have a workaround set the layoutmanager in code like this: set the isMeasurementCacheEnabled to false solves the problem

 rvPrices.layoutManager = LinearLayoutManager(context,LinearLayoutManager.HORIZONTAL,false).apply {
            isMeasurementCacheEnabled = false
        }