Today's 30-second #AndroidDev #Protip from +Roman Nurik is about improving performance by switching from view alpha to text color alpha.

Did you know that setting a View's alpha to anything but 1 incurs a performance penalty while setting a semitransparent text color on a TextView incurs no performance penalty whatsoever?*

The attached graphic illustrates a contrived example where switching from view alpha to text color alpha shrank frame rendering time 10x, allowing the framework to draw each frame in under 16ms to prevent jerky scrolling due to frame drops (one type of "jank").

Also note that Android 4.1+ optimizes simple cases, but if your TextView has a background set, uses Spannable text rather than a simple string, or has text selected, you'll run into this issue.

[*] Views with alpha must first be rendered to an offscreen buffer before being composited.
Photo
Shared publiclyView activity