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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:22:40+00:00 2026-06-07T12:22:40+00:00

When dragging a rectangular bitmap on android, I draw the bitmap using this as

  • 0

When dragging a rectangular bitmap on android, I draw the bitmap using this as per tons of example

//short cut code, after getting the new position from event
int x = event.x;
int y = event.y;
canvas.drawRect(bitmap, x - bitmapwidth/2,y-bitmapheight/2,null)

but this has some problem, if you have a wide bitmap and you happen to touch the left part
of the bitmap, the bitmap gets centered around the new touch coordinate from event.

is there a way to drag the bitmap and keeping the position relative to the drag point? just like how mouse drag behaves?

thanks

  • 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-07T12:22:41+00:00Added an answer on June 7, 2026 at 12:22 pm

    As for as I understand, you wish to drag a bitmap relative to the starting point when the finger touched down?

    This code should do the trick (if that is the case):

    boolean startCoordinatesDefined;
    Integer xStart;
    Integer yStart;
    
    if(touchdown) {
    if(startCoordinatesDefined == false) {
    startCoordinatesDefined = true;
    xStart = event.x;
    yStart = event.y;
    }
    canvas.drawRect(bitmap, event.x - xStart - bitmapwidth/2, event.y - yStart - bitmapheight/2, null);
    }
    else {
    startCoordinatesDefined = false;
    xStart = null;
    yStart = null;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am dragging on cells. using below code i am getting start cell text
I tried implementing dragging on android in 2 ways: Canvas with on draw. Relative
I'm using the code below for dragging an image ( #StndSoln1 ). It works
After dragging and dropping amount of documents to the server (roughly about 6gbs) using
How to change cursor when dragging using only CSS? div:active{ cursor:move; } This won't
After dragging two tables in from one database, I switch to another and drag
I am selecting time slot on dragging on Exam time cell. After selecting time
is this solution possible in asp.net dragging picturebox inside winform on runtime i just
I am working on Polygon Dragging , also Resizing of Polygon. I can draw
I was writing code for dragging mechanism which invokes to wait for small period

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.