看到别人写的这个效果不错,看了他的代码以及实现思路自己写了遍:
/**
* 带动画的checkBox
* Created by deadline.
*/
public class SmoothCheckBox extends View {
private static final String TAG = "SmoothCheckBox";
private static final String CHECK_VALUE = "check_value";
private static final String INSTANCE_STATE = "instance_state";
private static final float MIN_SCALE = 0.3f;
/**
* 圆环和背景的画笔
*/
private Paint mCirclePaint = null;
private float mMinScale = MIN_SCALE;
/**
* 对号的画笔
*/
private Paint mCorrectPaint = null;
/**
* 半径, 根据设置的宽高
*/
private float mRadius;
private float mCurrentValue;
private float mCurrentProgress;
private boolean mIsInDrawBackground;
/**
* 中心点
*/
private float centerX, centerY;
private float[] mPoint;
/**
* 动画时长
*/
private int mCircleDuration;
private int mCorrectDuration;
/**
* 背景颜色, 对勾颜色
*/
private int mBgCheckedColor;
private int mBgUnCheckedColor;
private int mCorrectColor;
/**
* 对勾的宽度
*/
private int mCorrectWidth;
/**
* 当前是否为选中状态
*/
private boolean mChecked;
private boolean misInAnim;
private AnimatorSet set = null;
private ArgbEvaluator argbEvaluator = null;
/**
* 是否在动画完成后调用OnCheckChange
*/
private boolean mIsActionAfterAnim;
private OnCheckedChangeListener mListener;
public interface OnCheckedChangeListener{
void OnCheckChange(SmoothCheckBox smoothCheckBox, boolean checked);
}
public SmoothCheckBox(Context context) {
this(context, null);
}