DrawHookView的实现

import android.content.Context;
import android.graphics.Canvas;
 import android.graphics.Paint;
import android.graphics.RectF;
import android.os.Handler;
 import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;


/**
 * DrawHook
 * Created by Zane on 2015/3/4.
 */
public class DrawHookView extends View {
    public static final String TAG = "DrawHookView";
    //绘制圆弧的进度值
    public 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;

    private boolean isStart;

    private Paint paint;

    public DrawHookView(Context context) {
        super(context);
        init();
    }

    public DrawHookView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public DrawHookView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    //绘制

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        progress += 3;
        //获取圆心的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--;
                if (line2_x > radius) {
                    mHandler.removeCallbacks(r);
                }
            }
            //画第二根线
            canvas.drawLine(center1 + line1_x - 1, center + line1_y, center1 + line2_x, center + line2_y, paint);
        }

        //每隔10毫秒界面刷新
        // postInvalidateDelayed(10);
        if (!isStart) {
            isStart = true;
            mHandler.postDelayed(r, 10);
        }

    }

    Handler mHandler = new Handler();
    Runnable r = new Runnable() {

        @Override
        public void run() {
            mHandler.postDelayed(r, 10);
            postInvalidate();
        };
    };

    private void init(){
        /**
         * 绘制圆弧
         */
         paint = new Paint();
        //设置画笔颜色
        paint.setColor(getResources().getColor(R.color.colorAccent));
        //设置圆弧的宽
        paint.setStrokeWidth(8);
        //设置圆弧为空心
        paint.setStyle(Paint.Style.STROKE);
        //消除锯齿
        paint.setAntiAlias(true);
        ViewGroup d;
    }


}







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值