Android draw point

纵然是瞬间 提交于 2019-12-10 11:16:44

问题


how to draw full circle or point with canvas? I using canvas and path + paint classes

my code:

@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;
}

回答1:


You can draw Circle by overriding onDraw() of your custom view. Check following link for drawing basics - http://developer.android.com/training/custom-views/custom-drawing.html

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

Also, similar replies are here - How to draw circle by canvas in Android?




回答2:


Your paint must be "full", for that you must write this

paint.setStyle(Paint.Style.FILL);

then just draw your circle

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

I hope it will be helpfull



来源:https://stackoverflow.com/questions/24038730/android-draw-point

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!