robinhood / ticker

An Android text view with scrolling text change animation
https://medium.com/robinhood-engineering/hello-ticker-20eaf6e51689
Apache License 2.0
4.38k stars 462 forks source link

Fix checkForRelayout to not depend on measure mode #27

Closed jinatonic closed 8 years ago

jinatonic commented 8 years ago

The problem with using MeasureSpec.mode is that it will eventually converge to EXACTLY as we set custom measurements (even with calling super.onMeasure with the provided measure mode). Once it converges to EXACTLY, the width and height will never change until the parent view forces the child to remeasure itself.

Rather than keeping the boolean flags, let's just keep the last measured desiredWidth and desiredHeight so we can use those to check for relayout. This will bypass the problem of the view's width always greater than the desired width (e.g. match_parent) and unnecessarily forcing requestLayout on every animation.