带酷炫动画的checkbox

本文介绍了如何实现一个带有动画效果的Checkbox,作者通过参考他人的代码并理解其实现原理,亲自实践完成了一个类似的酷炫动画Checkbox。文章适合对Android动画和自定义视图感兴趣的开发者阅读。
摘要由CSDN通过智能技术生成

这里写图片描述
看到别人写的这个效果不错,看了他的代码以及实现思路自己写了遍:

/**
 * 带动画的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);
    }

    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值