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 8040929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:03:17+00:00 2026-06-05T04:03:17+00:00

I want to draw the lines between points on the view, and then pull

  • 0

I want to draw the lines between points on the view, and then pull those points upto desired positions even the shape will change.

i know how to draw the line between two points canvas.drawLine(10, 10, 90, 10, paint); by using this i can draw the lines between points.

EDIT : here i am attaching image for clear explanation, from Paul answer now i am able to draw the lines between points, still have the problem of pulling points…

enter image description here

  • 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-05T04:03:19+00:00Added an answer on June 5, 2026 at 4:03 am

    Here’s how it’s done. Suppose you have your points, make these global:

    PointF topLeft = new PointF(10,10);
    PointF topRight = new PointF(90,10);
    PointF bottomLeft = new PointF(10,90);
    PointF bottomRight = new PointF(90,90);
    

    What you need to do is make a RectF around each point. The bigger the RectF, the bigger the touch area for the point is.

    float sizeOfRect = 5f;
    RectF topLeftTouchArea = new RectF(topLeft.x - sizeOfRect, topLeft.y - sizeOfRect, topLeft.x + sizeOfRect, topLeft.y + sizeOfRect);
    //Do this for the other points too
    

    Define some globals to keep track of what the user is doing in onTouch. One int is the corner being touched, and the other four are identifiers for the corners.

    private final int NONE = -1, TOUCH_TOP_LEFT = 0, TOUCH_TOP_RIGHT = 1, TOUCH_BOT_LEFT = 2, TOUCH_BOT_RIGHT = 3;
    int currentTouch = NONE;
    

    Now, in your onTouch event, you can check which point your user is touching in like this:

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
        //The user just put their finger down.
        //We check to see which corner the user is touching
        //And set our global, currentTouch, to the appropriate constant.
        case MotionEvent.ACTION_DOWN:
            if (topLeftTouchArea.contains(event.getX(), event.getY()) {
                currentTouch = TOUCH_TOP_LEFT;
            } else if (topRightTouchArea.contains(event.getX(),event.getY()) {
                currentTouch = TOUCH_TOP_RIGHT;
            } else if (botLeftTouchArea.contains(event.getX(),event.getY()) {
                currentTouch = TOUCH_BOT_LEFT;
            } else if (botRightTouchArea.contains(event.getX(), event.getY()) {
                currentTouch = TOUCH_BOT_RIGHT;
            } else {
                return false; //Return false if user touches none of the corners
            }
            return true; //Return true if the user touches one of the corners
        //Now we know which corner the user is touching.
        //When the user moves their finger, we update the point to the user position and invalidate.
        case MotionEvent.ACTION_MOVE:
            switch (currentTouch) {
            case TOUCH_TOP_LEFT:
                 topLeft.x = event.getX();
                 topLeft.y = event.getY();
                 //The bottom left x position has to move with the top left corner
                 bottomLeft.x = topLeft.x;
                 //The top right y position has to move with the top left corner
                 topRight.y = topLeft.y;
                 invalidate();
                 return true;
            case TOUCH_TOP_RIGHT:
                 topRight.x = event.getX();
                 topRight.y = event.getY();
                 //The top left y position has to move with the top right corner
                 topLeft.y = topRight.y;
                 //The bottom right x position has to move with the top right corner
                 bottomRight.x = topRight.x;
                 invalidate();
                 return true;
            case TOUCH_BOT_LEFT:
                 bottomLeft.x = event.getX();
                 bottomLeft.y = event.getY();
                 bottomRight.y = bottomLeft.y;
                 topLeft.x = bottomLeft.x;
                 invalidate();
                 return true;
            case TOUCH_BOT_RIGHT:
                 bottomRight.x = event.getX();
                 bottomRight.y = event.getY();
                 topRight.x = bottomRight.x;
                 bottomLeft.y = bottomRight.y;
                 invalidate();
                 return true;
            }
            //We returned true for all of the above cases, because we used the event
            return false; //If currentTouch is none of the above cases, return false
    
        //Here the user lifts up their finger.
        //We update the points one last time, and set currentTouch to NONE.
        case MotionEvent.ACTION_UP:
            switch (currentTouch) {
            case TOUCH_TOP_LEFT:
                 topLeft.x = event.getX();
                 topLeft.y = event.getY();
                 //The bottom left x position has to move with the top left corner
                 bottomLeft.x = topLeft.x;
                 //The top right y position has to move with the top left corner
                 topRight.y = topLeft.y;
                 invalidate();
                 currentTouch = NONE;
                 return true;
            case TOUCH_TOP_RIGHT:
                 topRight.x = event.getX();
                 topRight.y = event.getY();
                 //The top left y position has to move with the top right corner
                 topLeft.y = topRight.y;
                 //The bottom right x position has to move with the top right corner
                 bottomRight.x = topRight.x;
                 invalidate();
                 currentTouch = NONE;
                 return true;
            case TOUCH_BOT_LEFT:
                 bottomLeft.x = event.getX();
                 bottomLeft.y = event.getY();
                 bottomRight.y = bottomLeft.y;
                 topLeft.x = bottomLeft.x;
                 invalidate();
                 currentTouch = NONE;
                 return true;
            case TOUCH_BOT_RIGHT:
                 bottomRight.x = event.getX();
                 bottomRight.y = event.getY();
                 topRight.x = bottomRight.x;
                 bottomLeft.y = bottomRight.y;
                 invalidate();
                 currentTouch = NONE;
                 return true;
            }
            return false;
        }
    }
    

    What this does is make a rectangle around your point. Imagine drawing boxes around your points in the picture. These are the “touch pads” created by the Rect objects. The size of the rectangle is set by sizeOfRect. In the onTouchEvent, it checks each rectangle object to see if the user’s touch is inside the rectangle, signaling an the user trying to touch that point.

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

Sidebar

Related Questions

I have a program where I want to draw a line between two points.
I have Latitude and Longitude of two points and Want to Draw line between
I'm using pygame to draw a line between two arbitrary points. I also want
I want to draw two lines that go through three points, and make a
I want to draw a vertical line between the SectionIndex column and the cell
I'm implementing an application which want to draw lines in the panel. But the
I want to draw some lines and rectangles on a panel. Sometimes it does
I want to draw this in my view to draw this line, I have
In flash, I use lineTo to draw a line between two points. This is
Hello i have designed a maze and i want to draw a path between

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.