|
12 | 12 | import android.support.annotation.Nullable;
|
13 | 13 | import android.util.AttributeSet;
|
14 | 14 | import android.view.View;
|
| 15 | +import android.view.animation.DecelerateInterpolator; |
15 | 16 |
|
16 | 17 | /**
|
17 | 18 | * Created by 陈岗不姓陈 on 2017/10/17.
|
@@ -60,6 +61,9 @@ public class TickView extends View {
|
60 | 61 | //勾的偏移
|
61 | 62 | private float tickRadiusOffset;
|
62 | 63 |
|
| 64 | + //最后扩大缩小动画中,画笔的宽度的最大倍数 |
| 65 | + private static final int SCALE_TIMES = 6; |
| 66 | + |
63 | 67 | private OnCheckedChangeListener mOnCheckedChangeListener;
|
64 | 68 | private TickAnimatorListener mTickAnimatorListener;
|
65 | 69 |
|
@@ -135,14 +139,13 @@ private void initAnimatorCounter() {
|
135 | 139 | mRingAnimator.setInterpolator(null);
|
136 | 140 | //收缩动画
|
137 | 141 | ObjectAnimator mCircleAnimator = ObjectAnimator.ofInt(this, "circleRadius", radius - 5, 0);
|
138 |
| - mCircleAnimator.setInterpolator(null); |
| 142 | + mCircleAnimator.setInterpolator(new DecelerateInterpolator()); |
139 | 143 | mCircleAnimator.setDuration(mCircleAnimatorDuration);
|
140 | 144 | //勾出来的透明渐变
|
141 | 145 | ObjectAnimator mAlphaAnimator = ObjectAnimator.ofInt(this, "tickAlpha", 0, 255);
|
142 | 146 | mAlphaAnimator.setDuration(200);
|
143 |
| - mAlphaAnimator.setStartDelay(100); |
144 | 147 | //最后的放大再回弹的动画,改变画笔的宽度来实现
|
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); |
146 | 149 | mScaleAnimator.setInterpolator(null);
|
147 | 150 | mScaleAnimator.setDuration(mScaleAnimatorDuration);
|
148 | 151 |
|
@@ -210,8 +213,9 @@ private int getMySize(int defaultSize, int measureSpec) {
|
210 | 213 | @Override
|
211 | 214 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
212 | 215 | 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); |
215 | 219 |
|
216 | 220 | height = width = Math.max(width, height);
|
217 | 221 |
|
|
0 commit comments