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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:01:01+00:00 2026-06-10T11:01:01+00:00

I am using MotionEvent and Matrix to drag my bitmap but instead the bitmap

  • 0

I am using MotionEvent and Matrix to drag my bitmap but instead the bitmap gets “translated” to a nearby region (most of the times in the opposite direction of press). I want to be able to drag it using Matrix translations. Here’s my code.

switch(action){
        case MotionEvent.ACTION_DOWN: {
            final float touchX = event.getX();
            final float  touchY = event.getY();
          //check to see if the user is pressing  at most 80 pixels far from the bitmap 
            if(((Math.abs(touchX - player.prevX)<=80) && ((Math.abs(touchY - player.prevY)<=80)))){
                 //if so then proceed to drag it to a new location
                player.isDraggable = true;
            }
            break;
        }
        case MotionEvent.ACTION_MOVE: {
            if(player.isDraggable){
                player.x = event.getX();
                player.y = event.getY();                    
                float dx = player.x - player.prevX, dy = player.y - player.prevY;
                player.matrix.postTranslate(dx, dy);
                player.prevX = player.x;
                player.prevY = player.y;
                player.isDraggable = false; 
        }
            break;
        }
    }
public void draw(Canvas canvas) {       
        canvas.drawBitmap(background, 0, 0, null);
        canvas.drawBitmap(player.bmp, player.matrix, null);
       for(int i=0;i<particles.size();i++){
           particles.get(i).drawShower(canvas);
        }    

}
  • 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-10T11:01:03+00:00Added an answer on June 10, 2026 at 11:01 am
    1. Your onTouch() method should return true to be able to get
      continuously values from the MotionEvent.
    2. You set the isDraggable attribute of your player immediately to
      false, when an attempt to drag the image appears. After that, you check each time, if it is true, but it wont be. I don’t know, what is the logic behind that, but try something else!
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using: @Override public boolean onTouchEvent(MotionEvent event) { I'm using surfaceview. But when I
i am trying to call the MotionEvent.obtain Methode using the reflections library. But so
All I achieve now is using onTouch(View v, MotionEvent event) event to get the
I'm currently using the event @Override public boolean onTouchEvent(MotionEvent ev) { To provide feedback
I'm getting screen coordinates using this: @Override public boolean onTouchEvent(MotionEvent ev) { x =
I am using Gesture Listner to acheive Swipe screen navigation. But it is not
I am using table layout to display data, but i want it to behave
Im developing a 2d game rightnow. Im using: @Override public boolean onTouchEvent(MotionEvent event) {
I am using the android touch sample from android developers blog, but the touch
im having a single Bitmap in a surfaceview. I am using multi touch to

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.