Have an app with few dragable custom font TextView
's.
Have created a class TextAnimator
which initiates single ValueAnimator
and allows to add wanted TextViews which are set as setText(textValue, BufferType.SPANNABLE);
.
By adding a new TextView
to this TextAnimator
, it stores a TextView
, arrays of initial/end random colors and Spannable
variables for each letter in ArrayLists
of simple arrays.
On UpdateListener
of ValueAnimator
I iterate through all added TextViews
, calculate color transition values and change color of each letter like this (according to suggestion here: Change text color of one word in a TextView):
listOfSpannables.get(indexLocation).setSpan(new ForegroundColorSpan(Color.HSVToColor(listOfHSVs.get(indexLocation)[i])), i, i+1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
This animation makes my app work (dragging, other animations) very sluggish and Im not sure what is causing it. My guess is that maybe using of spannables is inappropriate (maybe I should somehow clear all added spannables before re-adding them on each iteration - how to clear them all at once?).
I could also use HTML to set color of each letter, if that would be faster. Or maybe whole approach is wrong.
Any suggestions, tips on how to improve performance?