我真正想要的是一个弧线移动的效果看起来像流星从天而降的动画,你可以在LG G3的圆形外壳小窗口上看到动画,每次关闭外壳时,动画都会在环周围发光,查看此视频,来自 youtube(您可以在 00:18、00:30、01:18、01:29 ... 看到它):
https://www.youtube.com/watch?v=tEQpYms1bJA
我做了一点搜索,并编写了我的代码(参考this),但是绘制弧线的线条看起来很实心,没有我想要的效果,这是我的弧线绘制代码:
public class SideArcsView extends View{
private Paint mPaint;
private int parentWidth;
private int strokeWidth;
private RectF oval;
private static int INITIAL_LEFT_ARC_START_ANGLE = 225;
private static int INITIAL_RIGHT_ARC_START_ANGLE = 315;
private int startLeftArcAngle = INITIAL_LEFT_ARC_START_ANGLE;
private int startRightArcAngle = INITIAL_RIGHT_ARC_START_ANGLE;
private int arcAngle = 45;
public SideArcsView(Context mContext, int parentWidth) {
super(mContext);
this.parentWidth = parentWidth;
init();
}
private void init() {
strokeWidth = (12 * parentWidth) / 300;
initPaint();
initOval();
}
private void initPaint() {
mPaint = new Paint();
mPaint.setColor(Color.WHITE);
mPaint.setStrokeWidth(strokeWidth);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setAntiAlias(true);
mPaint.setStrokeCap(Paint.Cap.ROUND);
}
private void initOval() {
float padding = mPaint.getStrokeWidth() / 2;
oval = new RectF();
oval.set(padding, padding, parentWidth - padding, parentWidth - padding);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
drawArcs(canvas);
}
private void drawArcs(Canvas canvas) {
canvas.drawArc(oval, startLeftArcAngle, arcAngle, false, mPaint);
canvas.drawArc(oval, startRightArcAngle, -arcAngle, false, mPaint);
}
public void startRotateAnimation() {
ValueAnimator valueAnimator = ValueAnimator.ofInt(0, 136);
valueAnimator.setInterpolator(new DecelerateInterpolator());
valueAnimator.setDuration(2000);
valueAnimator.setRepeatCount(ValueAnimator.INFINITE);
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
startLeftArcAngle = INITIAL_LEFT_ARC_START_ANGLE - (int) animation.getAnimatedValue();
startRightArcAngle = INITIAL_RIGHT_ARC_START_ANGLE + (int) animation.getAnimatedValue();
invalidate();
}
});
valueAnimator.start();
}
public void startResizeDownAnimation() {
ValueAnimator valueAnimator = ValueAnimator.ofInt(45, 10);
valueAnimator.setInterpolator(new DecelerateInterpolator());
valueAnimator.setDuration(2000);
valueAnimator.setRepeatCount(ValueAnimator.INFINITE);
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
arcAngle = (int) animation.getAnimatedValue();
invalidate();
}
});
valueAnimator.start();
}
}
它看起来像:
有人能告诉我如何画出像 LG G3 的发光圆环这样的东西吗?请给我一些建议...