drawTimingThread.sendEmptyMessageDelayed(MSG_TOP_DRAW, animaTopIntervalTime);
invalidate();
break;
这是底部波纹扩散动画:
case MSG_RIPPLE_DRAW:
if (mBotCircleAnimaRadius < mBotCircleMaxRadius) {
mBotCircleAnimaRadius += topIntervalDistance * 8;
drawTimingThread.removeMessages(MSG_RIPPLE_DRAW);
drawTimingThread.sendEmptyMessageDelayed(MSG_RIPPLE_DRAW, animaBotIntervalTime);
// 透明度
mBotCirclePaint.setAlpha(getAlphaOfRipple());
invalidate();
} else {
mBotCircleAnimaRadius = 0;
drawTimingThread.removeMessages(MSG_RIPPLE_DRAW);
}
break;
View的跳动动画是使用的AnimatorSet组合动画,上车点的圆点文字效果就是简单绘制,就不细展开了。
…
// translationY先上后下
AnimatorSet mSet1 = new AnimatorSet();
mSet1.play(mTAnimator1).before(mTAnimator2);
mSet1.start();
栗子β
这个动画效果是通过View不断绘制实现的,用到了圆弧、bitmap和文字的绘制api。其中刻度线的绘制则是通过不断旋转canvas画布来实现的。
实现的难点是外围文字在环绕过程中,坐标位置的确认,即通过圆心坐标,半径,扇形角度,如何计算出扇形终射线与圆弧交叉点的x, y坐标,所幸网上都能找到解决方案及背后的数学模型,代码见下:
private void paintOutWord(Canvas canvas, String state) {
PointF progressPoint = CommentUtil.calcArcEndPointXY
(radius + getPaddingLeft() + specialScaleLineLength + scaleToRingSpace + wordWith
, radius + getPaddingTop() + specialScaleLineLength + scaleToRingSpace + wordHeigh
, radius + specialScaleLineLength + scaleToRingSpace
, progress * (360 / 100f), -90);
int left = (int) progressPoint.x;
int top = (int) progressPoint.y;
wordPaint.getTextBounds(state, 0, state.length(), rect);
if (left < radius + getPaddingLeft() + specialScaleLineLength + scaleToRingSpace + wordWith) {
left -= rect.width();
}
if (top > radius + getPaddingTop() &