开发者

Draw circle on view

开发者 https://www.devze.com 2023-04-10 20:55 出处:网络
I want to draw a circle when ever user touches any place on the screen.I know to draw the circle using canvas,but how the drawn circles should be positioned to screen?

I want to draw a circle when ever user touches any place on the screen.I know to draw the circle using canvas,but how the drawn circles should be positioned to screen?

Does the sur开发者_如何学JAVAface view help for me?

Thanks in advance.


You can use the Activity.onTouchEvent event to determine where the user touched the screen. Then you can draw your circle on the canvas at that position.

Here's an example that handles a simple touch event.

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        final int action = ev.getAction();
        switch (action & MotionEvent.ACTION_MASK) {
          case MotionEvent.ACTION_DOWN: {
            final float x = ev.getX();
            final float y = ev.getY();
            // draw circle at x,y
        }
   }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号