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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:35:41+00:00 2026-05-23T04:35:41+00:00

I have an ImageView that you can use to do a one-finger pan, or

  • 0

I have an ImageView that you can use to do a one-finger pan, or a two finger scale. It works fine. I’ve extended it to handle rotation, and its behaviour is causing some confusion.

When there’s a multi-touch event this method gets called, which should return an angle of rotation in degrees. It is not doing what I expect.

private int fingersAngle(MotionEvent event)
{
    float x = event.getX(0) - event.getX(1);
    float y = event.getY(0) - event.getY(1);
    int degrees = (int)(Math.toDegrees(Math.atan2(y, x)));
    return degrees;
}

As I rotate the two fingers I’d expect outputs like…

158 166 168 169 174 176 179 181 etc

But what I actually get is more like this:

158 166 -179 179 -179 179 -179

The problem seems to be with signs. How does this method know whether it’s 180 or -180, or 90 or -270? The image often rotates the wrong way, and then suddenly jumps and starts rotating the opposite way. Even worse, the direction it initially rotates is effectively random.

I’m testing the app using a Nexus One, but also see the same problem on an Advent Vega tablet. Both devices work ok with Google Maps in 3D to rotate the screen (if a bit jumpy sometimes) so the evidence doesn’t suggest a hardware limitation.

A secondary problem is that when the two fingers are approximately vertically or horizontally aligned the angle simply doesn’t change, so the rotation “sticks” for about 10-20 degrees top/bottom/left/right.

Currently I’m doing a check to see if the angle has suddenly changed a huge amount, and if so, to subtract it from 360. Ugly as hell, but it helps a little.

Hopefully one of you has seen this before and knows how to extract the angular rotation from a multi-touch gesture.

Some things in Android are so easy it’s amazing, but stuff like this is seriously painful.

  • 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-05-23T04:35:42+00:00Added an answer on May 23, 2026 at 4:35 am

    To make this work like users expect, you must keep some state.

    An arc-tangent will only tell you the angle between two points—an instantaneous snapshot of the system. But you are performing an animation—something that happens over time.

    So, I think that you are on the right track with your “ugly” solution that tries to detect large changes in the angle. What you really should be tracking over time is the position of each finger.

    Suppose a user is using their thumb and index finger to gesture. You need to make sure that their digits are consistently represented, e.g. the thumb is always represented by (x0, y0), and the index finger by (x1, y1).

    It’s likely that the device has some rule how each coordinate is reported. For example, maybe it will always report the upper-left coordinate in the “0” slot of the event, and the lower-right coordinate in the “1” slot. But if the user moves their thumb from lower-right to upper-left, you must make sure that you are still treating it as (x1, y1) in your angle formula, even though the device is now reporting it as (x0, y0) in the event. Otherwise, the image will appear to quickly flip 180°, back and forth.

    If the device doesn’t track fingers for you, you’ll have to come up with a heuristic for guessing. A simple, “which of the previous coordinates is closer to the current coordinate” would be a good place to start, but I could see the need for something fancier if the resolution of events is poor.

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

Sidebar

Related Questions

I have used ImageView's before and understand the different scale types that can be
I have: String uri = @drawable/myresource.png; How can I load that in ImageView? this.setImageDrawable?
I have a custom ListView and an ImageView that I'm trying to use as
How can I extend ImageView , so that I can use in my code
I have use a singleton class that contained just one passed value. I then
I have an ImageView that I am animating using a TranslateAnimation. At the end
I have an ImageView that is 250dp above the bottom and with translate animation
I have an ImageView in my activity that shows an active symbol when a
I have a ImageView and draw some things on that view. Now I want
I have a scrollview (IBOutlet); in that scrollview I have added an imageview. I

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.