自定义画圆形

自定义画圆形

public class ColorDotView extends View {

    int count = 0;

    public ColorDotView(Context context) {
        this(context, null);
    }

    public ColorDotView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ColorDotView(Context context, AttributeSet ats, int defaultStyle) {
        super(context, ats, defaultStyle);
    }


    @Override
    public boolean onKeyDown(int keyCode, KeyEvent keyEvent) {
        return true;
    }

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent keyEvent) {
        return true;
    }

    @Override
    public boolean onTrackballEvent(MotionEvent event) {
        int actionPerformed = event.getAction();
        return true;
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        invalidate();
        return true;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        canvas.drawColor(Color.BLACK);
        Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

        if (count % 8 == 0 | count % 8 == 1) {
            mPaint.setColor(Color.RED);
        } // circle color
        if (count % 8 == 2 | count % 8 == 3) {
            mPaint.setColor(Color.BLUE);
        }
        if (count % 8 == 4 | count % 8 == 5) {
            mPaint.setColor(Color.GREEN);
        } // circle color
        if (count % 8 == 6 | count % 8 == 7) {
            mPaint.setColor(Color.YELLOW);
        }

        ++count;

        //canvas.drawCircle(cx, cy,radios,paint);
        canvas.drawCircle(canvas.getWidth() / 2, canvas.getHeight() / 2,
                canvas.getWidth() / 4, mPaint);
    }
}

你可能感兴趣的:(自定义画圆形,android)