public class RightOrLeftView extends View {private Paint mPaint;private Path mPath;private ValueAnimator mAnimator;//可以主动传进来private int width;private int height;private Paint mCircleStrokePaint;private Paint mCirclePaint;private boolean mIsStart = false;private int mCircleRightColor=Color.GREEN;private int mPathRightColor=Color.WHITE;private int mCircleLeftColor=Color.WHITE;private int mPathLeftColor=Color.RED;private boolean mIsRight;public RightOrLeftView(Context context) {this(context, null);}public RightOrLeftView(Context context, AttributeSet attrs) {this(context, attrs, 0);}public RightOrLeftView(Context context, AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);mPath = new Path();width = dip2px(context, 60);height = dip2px(context, 60);//对号initStrokePaint();initCirclePaint();initPath();PathMeasure mPathMeasure = new PathMeasure(mPath, false);final float length = mPathMeasure.getLength();mAnimator = ValueAnimator.ofFloat(1, 0);mAnimator.setInterpolator(new LinearInterpolator());mAnimator.setDuration(1000);mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {@Overridepublic void onAnimationUpdate(ValueAnimator animation) {float fraction = (float) animation.getAnimatedValue();DashPathEffect mEffect = new DashPathEffect(new float[]{length, length}, fraction * length);mPaint.setPathEffect(mEffect);invalidate();}});}private void initPath() {mPaint = new Paint();mPaint.setStrokeWidth(5);mPaint.setStyle(Paint.Style.STROKE);mPaint.setColor(mIsRight?mPathRightColor:mPathLeftColor);if(mIsRight){mPath.reset();mPath.moveTo(width * 0.3f, height * 0.5f);mPath.quadTo(width / 2f, height + 10, width * 0.7f, height * 1 / 4);}else {mPath.reset();mPath.moveTo(width * 0.7f, height * 0.3f);mPath.lineTo(width * 0.3f, height * 0.7f);mPath.moveTo(width * 0.3f, height * 0.3f);mPath.lineTo(width * 0.7f, height * 0.7f);}}private void initStrokePaint() {mCircleStrokePaint = new Paint();mCircleStrokePaint.setDither(true);mCircleStrokePaint.setAntiAlias(true);mCircleStrokePaint.setColor(Color.BLACK);mCircleStrokePaint.setStyle(Paint.Style.STROKE);mCircleStrokePaint.setStrokeWidth(2);}private void initCirclePaint() {mCirclePaint = new Paint();mCirclePaint.setDither(true);mCirclePaint.setAntiAlias(true);mCirclePaint.setColor(mIsRight?mCircleRightColor:mCircleLeftColor);mCirclePaint.setStyle(Paint.Style.FILL);}@Overrideprotected void onDraw(Canvas canvas) {super.onDraw(canvas);//画对号if (mIsStart) {//画空心圆canvas.drawCircle(width / 2, width / 2, width / 2 - 10, mCirclePaint);//画实心圆canvas.drawCircle(width / 2, width / 2, width / 2 - 10, mCircleStrokePaint);canvas.drawPath(mPath, mPaint);}}public void start() {mIsStart = true;mAnimator.start();}/*** 根据手机的分辨率从 dip 的单位 转成为 px(像素)*/public static int dip2px(Context context, float dpValue) {final float scale = context.getResources().getDisplayMetrics().density;return (int) (dpValue * scale + 0.5f);}/*** 根据手机的分辨率从 px(像素) 的单位 转成为 dp*/public static int px2dip(Context context, float pxValue) {final float scale = context.getResources().getDisplayMetrics().density;return (int) (pxValue / scale + 0.5f);}public void setmIsRight(boolean mIsRight) {this.mIsRight = mIsRight;}
}

写到最后发现还是没办法合二为一 ,你可以手动把它拆成俩个View,

Andriod 对号错号相关推荐

  1. latex中的对号和错号

    介绍 除了大家耳熟能详的\checkmark和$\times$,在 LaTeX 文档里还可以用什么命令输入对号(Check Mark)和错号(X Mark / Cross Mark)呢?请见下文! 看 ...

  2. Android-手势识别(普通手势识别:上 下 左 右 ;自定义手势识别:对号,错号 等)

    1.回顾 上篇学习了 Android 系统服务的 10个实例 ,当然 还有更多的系统服务没有使用:留下来的遗憾就是,昨晚没有将demo下载地址分享出去: demo下载: http://download ...

  3. Excel快速输入对勾和错号

    Excel快速输入对勾和错号 : 但是工作量大了以后,插入特殊符号的劣势就显现出来了,这里有个快速输入对勾和错号的方法:按住 ALT 键,同时操作小键盘 "41420" -> ...

  4. JavaEE学习08(解决项目导入eclipse后项目中的红错号)

    解决项目中的红错号 一.出错如图所示 二.解决步骤 三.解决项目包红错号(代码没报错) 四.解决java compiler level does not match the version of th ...

  5. Excel 2010 对号叉号怎么打出来

    按小键盘数字键:Alt+41420  对号 按小键盘数字键:Alt+41642  叉号 http://jingyan.baidu.com/article/fdbd4277c228cdb89e3f482 ...

  6. mysql start sever_MySQL安装最后一步start server总是错号 ?

    MySQL 5.1 安装过程中报apply security setting错误的解决办法 1, 卸载MySQL 2, 删除目录 C:\Documents and Settings\All Users ...

  7. css怎么画错号,CSS3 对/错符号的切换动画

    CSS 语言: CSSSCSS 确定 .select { margin: 2rem; height: 40px; width: 200px; border: 1px solid #ededed; cu ...

  8. idea文件有个白色错号 文件灰色

    如图: 解决办法: pom右键 Mark as XML解决

  9. 【LaTex常用命令集】数学比较符号,字体形状,各种箭头+对号+叉号

    ▚ 01 数学比较符号 名称 命令 大于 \textgreater 大于等于 \ge 或 \geq (Greater than or Equal to的缩写) 小于 \textless 小于等于 \l ...

  10. latex中的对与错(对号√与叉号×)、空格

    转载 LaTeX 对号和错号_Xovee的博客-CSDN博客_latex对号错号 [转载]LaTeX中的空格汇总_AXYZdong的博客-CSDN博客_latex空格符号怎么打出来 空格 对号√ 错号 ...

最新文章

  1. 总是感觉时间不够用?程序员如何管理时间?
  2. Redis设计与实现
  3. springmvc学习笔记(10)-springmvc注解开发之商品改动功能
  4. 双11不过瘾?双十二低至半价继续抢,更有免费学的机会等你抢!
  5. 探索多媒体开发最新最佳实践(内附资料下载)
  6. jboss fuse 教程_在JBoss Fuse / Fabric8 / Karaf中使用Byteman
  7. Mysql运行在内核空间_思考mysql内核之初级系列6—innodb文件管理 | 学步园
  8. vb 垂直滚动条定位
  9. 可以让你少奋斗十年的工作经验
  10. outlook阅读html,Outlook HTML邮件中英文混排字体设置
  11. 拳王虚拟项目公社:利用减肥健身类虚拟资源项目,如何打造一套赚钱系统?
  12. ap.net core 教程(三)
  13. matlab Tricks(二十七)—— 可变输入参数输出参数的适配
  14. 万字长文丨大白话带你由浅入深Python编程语言
  15. debug工具_Hackintool for【黑】mac V3.4.4中文版 黑苹果必装工具箱
  16. 轻量级音乐服务器LMS
  17. GoF、J2EE 设计模式
  18. matlab tube函数,2015-08-25-OpenCV for Matlab Users (5) - OpenCV 自身易搞混的函数辨析
  19. Fluent 湍流非预混燃烧模拟
  20. 软件工程知识点复习第二章

热门文章

  1. python给矩阵赋值_python 实现矩阵旋转
  2. 基于PaddlePaddle2.0的蝴蝶图像识别分类——利用预训练残差网络ResNet101模型中参数的调整,数据增强
  3. mac定时备份mysql_定时备份mysql数据库
  4. Keil 中 Error L6002U
  5. Hive建表语句的中文注释乱码问题
  6. Chrom安装Axure插件浏览原型图
  7. 使用a标签下载文件时成了预览,并非是下载
  8. matlab 矩形窗汉明窗幅频特性对比
  9. 毕业论文编辑器软件制作经历与思考1
  10. 利用python爬取飞猪信息_飞猪爬虫项目