InstaMaterial icon indicating copy to clipboard operation
InstaMaterial copied to clipboard

Warning : requestLayout() improperly called

Open gmeral opened this issue 7 years ago • 1 comments

When the likes counter is updated, this warning appears in the console.

09-18 14:47:14.751 8414-8414/io.github.froger.instamaterial W/View: requestLayout() improperly called by android.support.v7.widget.AppCompatTextView{b2730f6 V.ED..... ......ID 0,0-143,57} during layout: running second layout pass

I also have a TextSwitcher in my RecyclerView items and when calling textSwitcher.setTextin my ItemAnimator, i also have this warning. Would you have an idea why this is happening and how we could avoid it ?

Thanks in advance for the help !

gmeral avatar Sep 18 '17 12:09 gmeral

I also encountered this and wanted to share my solve just in case someone else comes across this issue.

ItemAnimator.recordPreLayoutInformation is called before RecyclerView.Adapter.onBindViewHolder and ItemAnimator.recordPreLayoutInformation after. To avoid rebinding the data and triggering request layout I flagged my ViewHolder to store the content data but not bind it to the views, I set a flag on the viewHolder in recordPreLayoutInformation and clear it when the first animation in the series started by animateChange is started (AnimatorListenerAdapter.onAnimationStart).

I encapsulate binding data to view in a method on my viewholder like bindTo(content: Content) and modified this method to check if the flag was set before setting the viewHolder's views

// ViewHolder snippet, Kotlin
var content: ContentType? = null
var isChangeAnimationScheduled = false
fun bindTo(newContent: ContentType) {
    content = newContent
    if(isChangeAnimationScheduled) return
    // Bind Content to views here
}

waterpoweredmonkey avatar Feb 01 '19 23:02 waterpoweredmonkey