Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning : requestLayout() improperly called #41

Open
gmeral opened this issue Sep 18, 2017 · 1 comment
Open

Warning : requestLayout() improperly called #41

gmeral opened this issue Sep 18, 2017 · 1 comment

Comments

@gmeral
Copy link

gmeral commented Sep 18, 2017

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 !

@waterpoweredmonkey
Copy link

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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants