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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:10:00+00:00 2026-06-16T21:10:00+00:00

I have a View which I want to be draggable so I’ve overridden its

  • 0

I have a View which I want to be draggable so I’ve overridden its onTouchEvent(MotionEvent event) method and, on move events, I reposition/translate my View based on the event action’s (x, y) coordinates. However! On dragging my View right – for example – I’m seeing that the event action’s x co-ordinate is not increasing steadily (i.e. … 15, 16, 17, 18…) but is interleaved instead (i.e. … 15, 23, 16, 24, 17, 25 …) and thus my View moves in a jerked manner. (Likewise for dragging left, up, down etc.)

Anyone know why this might be and how I can avoid it?!

Here’s my onTouchEvent(..) method…

@Override
public boolean onTouchEvent(MotionEvent event)
{
  switch (event.getAction())
  {
  case MotionEvent.ACTION_DOWN:
    // make note of the down action's (x, y) coordinate
    action_down_x = event.getX();
    action_down_y = event.getY();
    return true;
  case MotionEvent.ACTION_MOVE:
    // work out displacement
    dX = event.getX() - action_down_x;
    dY = event.getY() - action_down_y;
    // code here to move the view
    return true;
  case MotionEvent.ACTION_UP:
    return true;
  }

  return super.onTouchEvent(event);
}
  • 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-16T21:10:01+00:00Added an answer on June 16, 2026 at 9:10 pm

    The problem is pretty simple: You are working with two relative coordinates. If you override the onTouchEvent() from the view, you might get a value 10,10. If you now move the finger, you get a new value, lets say 9,9 so you change the position of the view which would result in the fact, that your finger is at 10,10 of the view coordinate system again.

    What I would do: Override the onTouchEvent() of the parent, so that you stay in the same coordinate system. Your implementation looks good, so it should work easily when you just move the code to the parent view/activity.

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

Sidebar

Related Questions

I have Grouped Table View in which I want to display Contact details. But
I have a django view generating a bunch of data which I want to
I have a custom view with several NSTextField controls for which I want to
I have a user database which I want the admin to be able view
I have outline view each element of which is checkbox. I want to set
In my view files, I have soundbites which i want to play through a
I want to implement this view But I have one question: The text which
I have a navigation controller which also has a table view. I want to
I do have a view, which looks like this atm: I want that first
I have a detail view Fragment which I want to scroll Horizontally as well

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.