Assigned
Status Update
Comments
ma...@gmail.com <ma...@gmail.com> #2
one more workaround is
fun RecyclerView.executeAfterAllAnimationsAreFinished(
callback: (RecyclerView) -> Unit
) = post(
object : Runnable {
override fun run() {
if (isAnimating) {
//if isAnimating() returned true itemAnimator will be non-null
itemAnimator!!.isRunning {
post(this)
}
} else {
callback(this@executeAfterAllAnimationsAreFinished)
}
}
}
)
fun RecyclerView.executeAfterAllAnimationsAreFinished(
callback: (RecyclerView) -> Unit
) = post(
object : Runnable {
override fun run() {
if (isAnimating) {
//if isAnimating() returned true itemAnimator will be non-null
itemAnimator!!.isRunning {
post(this)
}
} else {
callback(this@executeAfterAllAnimationsAreFinished)
}
}
}
)
ki...@google.com <ki...@google.com>
mi...@gmail.com <mi...@gmail.com> #3
To fix it:
- set horizontal constraints in recycler view
- set recycler view
layout_width
to 0dp
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical"
android:overScrollMode="ifContentScrolls"
android:scrollbars="vertical"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/headerTextView"
tools:listitem="@layout/list_item" />
lb...@gmail.com <lb...@gmail.com> #4
@3 Why should there be a difference between horizontal constraints with size 0, and just match_parent?
They are supposed to be the same.
The workaround helped, but this doesn't mean there is no bug.
In fact you show there is another bug: there is a difference between those 2 cases.
They are supposed to be the same.
The workaround helped, but this doesn't mean there is no bug.
In fact you show there is another bug: there is a difference between those 2 cases.
im...@gmail.com <im...@gmail.com> #5
worked for me
im...@gmail.com <im...@gmail.com> #6
#3 worked for me
ag...@gmail.com <ag...@gmail.com> #7
How can we reproduce this issue?
[Deleted User] <[Deleted User]> #8
#3 not working for me. The view size become 0 and no element is displayed.
na...@gmail.com <na...@gmail.com> #9
Is this going to be fixed?
pa...@gmail.com <pa...@gmail.com> #10
Are you planning to fix this?
ch...@gmail.com <ch...@gmail.com> #11
Any update on this?
Description
1. ConstraintLayout that has RecyclerView in it.
2. The ConstraintLayout is inside ViewAnimator.
3. RecyclerView gets its data changed, animating items
4. Before the animation of the RecyclerView ends, the ViewAnimator switches to another view.
This causes an exception and a crash, of :
"
java.lang.IllegalArgumentException: Tmp detached view should be removed from RecyclerView before it can be recycled
"
More people have reported about this here:
Currently, there are some workarounds that I've found for this:
1. Use LinearLayout instead of ConstraintLayout
2. Temporarily set no animation to the RecyclerView in case of clearing its data, and restoring it shortly after:
val itemAnimator = recyclerView.itemAnimator
recyclerView.itemAnimator = null
clearItems()
recyclerView.itemAnimator = itemAnimator
Tested on Pixel 4 Android 10.
Dependencies:
implementation 'com.google.android.material:material:1.2.0-alpha04'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.recyclerview:recyclerview:1.2.0-alpha01'
implementation 'androidx.collection:collection-ktx:1.1.0'
implementation 'androidx.core:core-ktx:1.3.0-alpha01'
implementation 'androidx.fragment:fragment-ktx:1.2.0'