Apparently, I don't have enough reputation to comment on jburns20's answer, but I feel that my discovery will help those who are faced with its solution.
I noticed that there was a significant backwardness in my animation after I tried the jburns20 class. Through tracking, it became clear that the culprit repeatedly assigned a font resource. In my use case (and I'm sure many others), there is no need to repeatedly extract the font resource for each iteration.
Moving the instance before the loop solved the performance issues for me. For clarity, I reproduced my modification below, all credits should be sent to jburns20
public class CustomFontPagerTitleStrip extends PagerTitleStrip { //Moved typeface instantiation here, only required once. Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/xyz.ttf"); public CustomFontPagerTitleStrip(Context context) { super(context); } public CustomFontPagerTitleStrip(Context context, AttributeSet attrs) { super(context, attrs); } protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); for (int i=0; i<this.getChildCount(); i++) { if (this.getChildAt(i) instanceof TextView) { ((TextView)this.getChildAt(i)).setTypeface(tf); } } } }
source share