@Override
public void draw(Canvas canvas, CharSequence text, int start, int end,
float x, int top, int y, int bottom, Paint paint) {
canvas.save();
canvas.drawText( text.toString(), x - startX, y, paint);
canvas.restore();
int measureText = (int) paint.measureText(text, 0, text.length());
if (valueAnimator == null ) {
initAnimator(measureText - mView.getWidth());
}
}
private int startX = 0 ;
private final static int DEFULT_DURATION = 2000 ;
private int duration = DEFULT_DURATION ;
@Override
public int getSize(Paint paint, CharSequence text, int start, int end,
FontMetricsInt fm) {
return 40;
}
private void initAnimator(int width ){
valueAnimator = ValueAnimator.ofInt(0, width , 0 );
valueAnimator.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
startX = (Integer) animation.getAnimatedValue() ;
mView.invalidate();
}
});
valueAnimator.setInterpolator(new LinearInterpolator());
valueAnimator.setDuration(duration);
valueAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationRepeat(Animator animation) {
if (mEasySpanListener != null ) {
mEasySpanListener.over();
}
}
});
valueAnimator.setRepeatCount(Integer.MAX_VALUE);
valueAnimator.start();
}