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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:53:17+00:00 2026-06-06T22:53:17+00:00

I am trying to rotate image single round from it’s center point but I

  • 0

I am trying to rotate image single round from it’s center point but I am not able to stop at desire position as I can do rotation but I want to stop rotation after 360'(1 round).

public class RotateRoundActivity extends Activity implements OnTouchListener
{

    private ImageView dialer;
    //private float y=0;
    private float x=0;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        dialer = (ImageView) findViewById(R.id.big_button);
        dialer.setOnTouchListener(this);
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
    //  double r=Math.atan2(event.getX()-dialer.getWidth()/2, dialer.getHeight()/2-event.getY());

        double r=Math.atan2(event.getX()-dialer.getWidth()/2, dialer.getHeight()/2-event.getY());
        int rotation=(int)Math.toDegrees(r);
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                break;
            case MotionEvent.ACTION_MOVE:
                x=event.getX();
              //  y=event.getY();
                updateRotation(rotation);
                break;
            case MotionEvent.ACTION_UP:
                break;
        }//switch       

        return true;
    }

Rotation method@

    private void updateRotation(double rot){
        float newRot=new Float(rot);
        Bitmap bitmap=BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher);
        Matrix matrix=new Matrix();
        matrix.postRotate(newRot,bitmap.getWidth(),bitmap.getHeight());
        Log.i("demo===>", "matrix==>" + matrix);
     //   Log.i("demo===", "y===>" + y);
        Log.i("demo===", "x===>" + x);

        if(x>250){
            Bitmap reDrawnBitmap=Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,true);
            dialer.setImageBitmap(reDrawnBitmap);
        }
        else{
            Bitmap reDrawnBitmap=Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,true);
            dialer.setImageBitmap(reDrawnBitmap);
        }
    }

}

Your suggestions are appreciable.

  • 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-06T22:53:20+00:00Added an answer on June 6, 2026 at 10:53 pm

    You have to save previous rot value. And add check in updateRotation method if previousRot is at the left of 360′ degrees and rot is at the right of 360′ degrees then we made 1 round and need stop rotating.

    Sample code for clockwise case

    if (previousRot >= 300 && previousRot <= 360 && rot >= 0 && rot <= 60) {
        rot = 359.99; // or here can be 360'
    }
    

    For counter clockwise case it is almost the same, but the values swapped

    if (previousRot >= 0 && previousRot <= 60 && rot >= 300 && rot <= 360) {
        rot = 0;
    }
    

    This code will stop rotation. From the beginning previousRot should be 0 for clockwise case and 359.99 for counter clockwise


    Another approach is to add one more variable to store total traveled angle. From the beginning traveledAngle have to be equal to 0. And if you’re rotating in clockwise direction you have to increase it by the difference between rot and previousRot. When rotating counter clockwise decrease it by the same value.

    traveledAngle += rot - previousRot;
    

    When traveledAngle becomes greater than 360′ you need to stop rotating in clockwise direction, and when it becomes less than 0, you need to stop rotating in counter clockwise direction.

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

Sidebar

Related Questions

I am not able to understand how to rotate the image. I am trying
I'm trying to rotate a node around a custom center point in Ogre3D, but
I am trying to rotate an image of wheel continuously. I was able to
I am trying to rotate an image in Java, but when I do the
I'm trying to rotate an image, but it's getting slightly messed up when I'm
I am trying to rotate image, but I want to maintain the size of
I am trying to rotate an image using slider..its working well but when i
HEllo, I am trying to rotate a circular image around the center and then
I am trying to rotate an image from sdcard and then save back to
I am trying to rotate text on a background-image but my background image is

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.