标签:
TextView都有跑马灯的效果,如果说让你去监听跑马灯效果的执行,我觉得这个需求有点二了,但是也要实现。@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(); | |
} |
标签:
原文地址:http://www.cnblogs.com/flyme2012/p/848e3dc5c8f17a82c7d1d6e095e93352.html