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.
The problem with using
MeasureSpec.mode
is that it will eventually converge toEXACTLY
as we set custom measurements (even with callingsuper.onMeasure
with the provided measure mode). Once it converges toEXACTLY
, 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 forcingrequestLayout
on every animation.