Skip to content

Commit 585c9b0

Browse files
committed
更改动画配置速度的默认数值,并且收缩到圆心的动画增加一个插值器
1 parent 8f76e4f commit 585c9b0

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

library/src/main/java/com/github/chengang/library/TickRateEnum.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
enum TickRateEnum {
1111

12-
SLOW(600, 300, 450),
13-
NORMAL(400, 200, 300),
14-
FAST(200, 100, 150);
12+
SLOW(800, 480, 720),
13+
NORMAL(500, 300, 450),
14+
FAST(300, 180, 270);
1515

1616
public static final int RATE_MODE_SLOW = 0;
1717
public static final int RATE_MODE_NORMAL = 1;

library/src/main/java/com/github/chengang/library/TickView.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import android.support.annotation.Nullable;
1313
import android.util.AttributeSet;
1414
import android.view.View;
15+
import android.view.animation.DecelerateInterpolator;
1516

1617
/**
1718
* Created by 陈岗不姓陈 on 2017/10/17.
@@ -60,6 +61,9 @@ public class TickView extends View {
6061
//勾的偏移
6162
private float tickRadiusOffset;
6263

64+
//最后扩大缩小动画中,画笔的宽度的最大倍数
65+
private static final int SCALE_TIMES = 6;
66+
6367
private OnCheckedChangeListener mOnCheckedChangeListener;
6468
private TickAnimatorListener mTickAnimatorListener;
6569

@@ -135,14 +139,13 @@ private void initAnimatorCounter() {
135139
mRingAnimator.setInterpolator(null);
136140
//收缩动画
137141
ObjectAnimator mCircleAnimator = ObjectAnimator.ofInt(this, "circleRadius", radius - 5, 0);
138-
mCircleAnimator.setInterpolator(null);
142+
mCircleAnimator.setInterpolator(new DecelerateInterpolator());
139143
mCircleAnimator.setDuration(mCircleAnimatorDuration);
140144
//勾出来的透明渐变
141145
ObjectAnimator mAlphaAnimator = ObjectAnimator.ofInt(this, "tickAlpha", 0, 255);
142146
mAlphaAnimator.setDuration(200);
143-
mAlphaAnimator.setStartDelay(100);
144147
//最后的放大再回弹的动画,改变画笔的宽度来实现
145-
ObjectAnimator mScaleAnimator = ObjectAnimator.ofFloat(this, "ringStrokeWidth", mPaintRing.getStrokeWidth(), mPaintRing.getStrokeWidth() * 6f, mPaintRing.getStrokeWidth() / 6f);
148+
ObjectAnimator mScaleAnimator = ObjectAnimator.ofFloat(this, "ringStrokeWidth", mPaintRing.getStrokeWidth(), mPaintRing.getStrokeWidth() * SCALE_TIMES, mPaintRing.getStrokeWidth() / SCALE_TIMES);
146149
mScaleAnimator.setInterpolator(null);
147150
mScaleAnimator.setDuration(mScaleAnimatorDuration);
148151

@@ -210,8 +213,9 @@ private int getMySize(int defaultSize, int measureSpec) {
210213
@Override
211214
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
212215
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
213-
int width = getMySize((radius + dp2px(mContext, 2.5f) * 6) * 2, widthMeasureSpec);
214-
int height = getMySize((radius + dp2px(mContext, 2.5f) * 6) * 2, heightMeasureSpec);
216+
//控件的宽度等于动画最后的扩大范围的半径
217+
int width = getMySize((radius + dp2px(mContext, 2.5f) * SCALE_TIMES) * 2, widthMeasureSpec);
218+
int height = getMySize((radius + dp2px(mContext, 2.5f) * SCALE_TIMES) * 2, heightMeasureSpec);
215219

216220
height = width = Math.max(width, height);
217221

0 commit comments

Comments
 (0)