效果图

CheckBox状态: Checked , UnChecked
动画分析:
1.UnChecked --> Checked , 圆由小变大(简单易实现),然后是对号的动画(后面分析怎么画对号)
2.Checked --> UnChecked , 显示对号消失动画,然后圆由大变小(简单易实现)
---------------------------------------------------------------------------------------------------------
画的对号的位置分析

?
然后是画对号的动画分析

关键分析在图里,上代码
?
/*
* Created by Hanks
* Copyright (c) 2015 . All rights reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package rxandroid.zyh.com.rxandroid.custom;
import android.animation.ValueAnimator;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.LinearInterpolator;
/**
* Created by Administrator on 2015/5/14.
*/
public class TouchCheckBox extends View {
private Paint mCirclePaint;
private Paint mCorrectPaint;
private int radius; //圆的半径
private int width, height; //控件宽高
private int cx, cy; //圆心xy坐标
private float[] points = new float[6]; //对号的3个点的坐标
private float correctProgress;
private float downY;
private boolean isChecked;
private boolean toggle;
private boolean isAnim;
private int animDurtion = 150;
private OnCheckedChangeListener listener;
private int unCheckColor = Color.GRAY;
private int circleColor = Color.RED;
public TouchCheckBox(Context context) {
this(context, null);
}
public TouchCheckBox(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public TouchCheckBox(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public TouchCheckBox(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
/**
* 初始化
* @param context
*/
private void init(Context context) {
mCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCirclePaint.setColor(Color.RED);
mCirclePaint.setStyle(Paint.Style.FILL);
mCorrectPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCorrectPaint.setColor(Color.WHITE);
mCorrectPaint.setStyle(Paint.Style.FILL);
mCorrectPaint.setStrokeWidth(dip2px(context, 2));
setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (isChecked) {
hideCorrect();
} else {
showCheck();
}
}
});
}
/**
* 设置当前选中状态
* @param checked
*/
public void setChecked(boolean checked){
if (isChecked && !checked) {
hideCorrect();
} else if(!isChecked && checked) {
showCheck();
}
}
/**
* 返回当前选中状态
* @return
*/
public boolean isChecked(){
return isChecked;
}
/**
* 确定尺寸坐标
* @para