博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
android开发之实现动态打勾效果(DrawHookView)
阅读量:7102 次
发布时间:2019-06-28

本文共 2409 字,大约阅读时间需要 8 分钟。

今天产品中要实现这样的需求,想了想还是把它给整出来了! 

这里写图片描述

第一步:自定义View 

实现步骤: 
1、先画好圆弧 
2、再画第一根线 
3、最后再画第二根线

/** * DrawHook * Created by Zane on 2015/3/4. */public class DrawHookView extends View {    //绘制圆弧的进度值    private int progress = 0;    //线1的x轴    private int line1_x = 0;    //线1的y轴    private int line1_y = 0;    //线2的x轴    private int line2_x = 0;    //线2的y轴    private int line2_y = 0;    public DrawHookView(Context context) {        super(context);    }    public DrawHookView(Context context, AttributeSet attrs) {        super(context, attrs);    }    public DrawHookView(Context context, AttributeSet attrs, int defStyle) {        super(context, attrs, defStyle);    }    //绘制    @Override    protected void onDraw(Canvas canvas) {        super.onDraw(canvas);        progress++;        /**         * 绘制圆弧         */        Paint paint = new Paint();        //设置画笔颜色        paint.setColor(getResources().getColor(R.color.arc_blue));        //设置圆弧的宽度        paint.setStrokeWidth(5);        //设置圆弧为空心        paint.setStyle(Paint.Style.STROKE);        //消除锯齿        paint.setAntiAlias(true);        //获取圆心的x坐标        int center = getWidth() / 2;        int center1 = center - getWidth() / 5;        //圆弧半径        int radius = getWidth() / 2 - 5;        //定义的圆弧的形状和大小的界限        RectF rectF = new RectF(center - radius -1, center - radius -1 ,center + radius + 1, center + radius + 1);        //根据进度画圆弧        canvas.drawArc(rectF, 235, -360 * progress / 100, false, paint);        /**         * 绘制对勾         */        //先等圆弧画完,才话对勾        if(progress >= 100) {            if(line1_x < radius / 3) {                line1_x++;                line1_y++;            }            //画第一根线            canvas.drawLine(center1, center, center1 + line1_x, center + line1_y, paint);            if (line1_x == radius / 3) {                line2_x = line1_x;                line2_y = line1_y;                line1_x++;                line1_y++;            }            if (line1_x >= radius / 3 && line2_x <= radius) {                line2_x++;                line2_y--;            }            //画第二根线            canvas.drawLine(center1 + line1_x - 1, center + line1_y, center1 + line2_x, center + line2_y, paint);        }        //每隔10毫秒界面刷新        postInvalidateDelayed(10);    }}
第二步:布局文件引用自定义View

附colors.xml:

#10a679
#ffffff

https://github.com/ZaneLove/DrawHookView

你可能感兴趣的文章
商业模拟游戏:<柠檬汁杰克>项目源码
查看>>
额,看不出是男扮女装啊~~~~~~《绝地奶霸》
查看>>
Linux Shell 脚本限制ssh最大用户登录数
查看>>
我的友情链接
查看>>
VMware虚拟化部署带给我们的便利
查看>>
更新DB2数据表前的小注意
查看>>
我的友情链接
查看>>
springboot集成swagger2构建RESTful API文档
查看>>
日志分析(六)压测数据
查看>>
删除该目录下所有文件和子文件夹,但该根文件夹会保留
查看>>
织梦如何与discuz论坛整合一起应用
查看>>
Linux脚本实现远程自动备份
查看>>
dedecms基础语法
查看>>
HTML4.01规范中英文对照-有关SGML和HTML的一些事(2)
查看>>
nodejs-koa 中文档
查看>>
rhel5.6下安装oracle 11g
查看>>
saltstack自动部署apache实例
查看>>
电信技术培训AAA介绍
查看>>
docker_基础_2
查看>>
Zabbix系统数据采集方法总结
查看>>