Android绘制点

时间:2014-06-04 13:26:11

标签: android canvas point

如何用画布绘制整圆或点?我使用canvas和path + paint类

我的代码:

@Override
public boolean onTouchEvent(MotionEvent event) {
    float eventX = event.getX();
    float eventY = event.getY();
    System.out.println(event.getAction());
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        path.moveTo(eventX, eventY);
        return true;
    case MotionEvent.ACTION_MOVE:
        path.lineTo(eventX, eventY);
        break;
    case MotionEvent.ACTION_UP:
        path.addCircle(eventX, eventY, .1F, Path.Direction.CW);
        break;
    default:
        return false;
    }

    // Schedules a repaint.
    invalidate();
    return true;
}

2 个答案:

答案 0 :(得分:3)

您可以通过覆盖自定义视图的onDraw()来绘制圆圈。检查以下链接以了解绘图基础知识 - http://developer.android.com/training/custom-views/custom-drawing.html

protected void onDraw(Canvas canvas) {
 super.onDraw(canvas);
 canvas.drawCircle(x, y, radius, paint);
}

此外,类似的回复在这里 - How to draw circle by canvas in Android?

答案 1 :(得分:0)

你的油漆必须“满”,因为你必须写这个

paint.setStyle(Paint.Style.FILL);

然后只画你的圈子

canvas.drawCircle(x, y, radius, paint);

我希望它会有所帮助