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

Recalculating character spacing on text size change #68

Closed amitav13 closed 6 years ago

amitav13 commented 7 years ago

Hi, I've got a TickerView sitting inside a CoordinatorLayout. I'm making the text size smaller as the screen is scrolled up, using a CoordinatorLayout.Behavior and RecyclerView.OnScrollListener(). While the text size shrinks correctly, the character spacing doesn't seem to update. To illustrate:

screen shot 2017-10-25 at 6 22 50 pm

becomes

screen shot 2017-10-25 at 6 23 01 pm

Approaches that I've tried so far without success:

  1. Increasing right padding: If I set the right padding with the view width set to wrap_content, the view size increases. If I set it to a fixed width, the right edge of the view gets cropped.

  2. setAnimateMeasurementChange(true): Seems to have no effect.

  3. balance.setText(text): Retrieving and setting the same text on the view in hopes of triggering a remeasuring of the character widths.

  4. Calling balance.requestLayout() manually on every update, and a variety of permutations of using this combined with the other approaches above.

Is there another approach that you could suggest? Thanks!

amitav13 commented 7 years ago

Update: I've just tried this with the TickerView sitting in a plain old View class, to rule out any CoordinatorLayout issues. TickerView#setTextSize does not seem to recalculate character spacing in this scenario either.

jinatonic commented 6 years ago

Sorry for the late reply. I am able to repro the issue on the sample app, will investigate a fix.

amitav13 commented 6 years ago

Awesome, thanks. Is there a release planned for the near future?