Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8595673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:29:33+00:00 2026-06-12T00:29:33+00:00

In my app I need to draw a circle and user can drag it

  • 0

In my app I need to draw a circle and user can drag it anywhere on the screen .

To do this I have created a view, Drawn the circle in onDraw method. I tried to track the movements using onTouchEvent. But the circle is not really moving when I try to drag it rather its creating a new Circle wherever I touch the screen.

Please someone help me on this what im missing.

here’s my code

public class Circle extends View {

Paint paint, paintSmall;
private Point start = null;
private Point cursorAtMouseDown = null;
private Point startAtMouseDown = null;
private Point endAtMouseDown = null;
private boolean movingStart = false;
private boolean movingEnd = false;
private boolean movingLine = false;

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

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

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

private void init() {
    paint = new Paint();
    start = new Point(100, 100);
    paint.setColor(Color.BLUE);
    paint.setStrokeWidth(10);
    paint.setStyle(Paint.Style.STROKE);

}

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    paint.setStyle(Paint.Style.STROKE);
    canvas.drawCircle(start.x, start.y, 80, paint);

    canvas.drawCircle(start.x, start.y, 10, paint);

}

@Override
public boolean onTouchEvent(MotionEvent event) {

    Log.d("Inside On Touch", "");
    switch (event.getAction()) {
    case MotionEvent.ACTION_UP:

        if (movingStart || movingEnd || movingLine) {
            invalidate();
        }

        movingStart = false;
        movingEnd = false;
        movingLine = false;
        break;
    case MotionEvent.ACTION_OUTSIDE:
        if (movingStart || movingEnd || movingLine) {
            invalidate();
        }

        movingStart = false;
        movingEnd = false;
        movingLine = false;
        break;
    case MotionEvent.ACTION_MOVE:

        Log.d("Inside On Touch", "ACTION_MOVE");

        if (movingStart) {
            start.x = (int) event.getX();
            start.y = (int) event.getY();
            invalidate();
            Log.d("Inside On Touch", "--movingStart=" + movingStart);
            return true;
        } else if (movingEnd) {
            start.x = (int) event.getX();
            start.y = (int) event.getY();
            invalidate();
            Log.d("Inside On Touch", "--movingEnd=" + movingEnd);
            return true;
        } else if (movingLine) {
            Log.d("Inside On Touch", "--movingLine=" + movingLine);
            if (cursorAtMouseDown != null) {
                // double diffX = event.getX() - cursorAtMouseDown.x;
                // double diffY = event.getY() - cursorAtMouseDown.y;
                // start.x = (int) (startAtMouseDown.x + diffX);
                // start.y = (int) (startAtMouseDown.y + diffY);

                start = cursorAtMouseDown;

                invalidate();
                return true;
            }

        }
        return false;

    case MotionEvent.ACTION_DOWN:
        cursorAtMouseDown = new Point((int) event.getX(),
                (int) event.getY());

        if (cursorAtMouseDown.equals(start)) {

        }

        if (isCircleCenterChaged(cursorAtMouseDown)) {
            movingLine = true;
        }

        return true;

    default:
        return super.onTouchEvent(event);

    }
    return false;
}


}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:29:35+00:00Added an answer on June 12, 2026 at 12:29 am

    I m not sure but if you mannage below variable then it can solve your problem:

    private Point cursorAtMouseDown = null; 
    private Point startAtMouseDown = null; 
    private Point endAtMouseDown = null; 
    private boolean movingStart = false; 
    private boolean movingEnd = false; 
    private boolean movingLine = false; 
    

    Please manage boolean variable and mouse movement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a drawing app where the user can draw lines with their finger,
I am making an app that allows the user to draw on the screen
I need to draw a circle as per my finger move so i have
In my app I need to draw a widget contents onto Bitmap. The code(pseudo)
my app need to show user scrollable menu bar under tab bar like fox
Android Calendar App I need to be able to implement a view similar to
I need to draw a Gantt-Chart within my iPad App. Are there any frameworks
In my app, I need to draw a path where every coupe of frames,
I have a canvas-based drawing app that when zoomed in, I draw a miniature
I'm developing an App, and I need to draw borders and separators on a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.