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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:45:48+00:00 2026-05-30T11:45:48+00:00

hi in my app i am trying to rotate button about its centre but

  • 0

hi in my app i am trying to rotate button about its centre but it is not rotating based on its center instead it is moving from its position.below is my code please help me how to solve that issue.

 public class example extends Activity {
float newAngle,oldAngle=0;


int flag=0;
int n=340;
 RotateAnimation animation,animation1;

    Button arrow;
    Button left,right;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
     arrow=(Button)findViewById(R.id.img);
     left=(Button)findViewById(R.id.left);
     right=(Button)findViewById(R.id.right);
    final int width = arrow.getWidth();
    final int height = arrow.getHeight();      

     left.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if(flag>=0)
            {
                   newAngle = oldAngle+ 30;

                    oldAngle=newAngle;
            }
            flag++;
            Log.i("flag",""+flag);
             animation = new RotateAnimation(oldAngle, newAngle);
             animation.setFillAfter(true);
             animation.setDuration(200);
             arrow.startAnimation(animation);
        }
    });
     }
       }
  • 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-30T11:45:49+00:00Added an answer on May 30, 2026 at 11:45 am

    full example:

     public class MyActivity extends Activity implements View.OnClickListener {
    
        private ImageView _image;
        private float _newAngle, _oldAngle;
    
    
        /**
         * Called when the activity is first created.
         */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            Button button = (Button) findViewById(R.id.button);
            button.setOnClickListener(this);
            _image = (ImageView) findViewById(R.id.image);
        }
    
        public void onClick(View view) {
            if (view.getId() == R.id.button) {
                _newAngle = _oldAngle + 30;
    
                LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) _image.getLayoutParams();
                int centerX = layoutParams.leftMargin + (_image.getWidth()/2);
                int centerY = layoutParams.topMargin + (_image.getHeight()/2);
                RotateAnimation animation = new RotateAnimation(_oldAngle, _newAngle, centerX, centerY);
                animation.setDuration(0);
                animation.setRepeatCount(0);
                animation.setFillAfter(true);
                _image.startAnimation(animation);
    
                _oldAngle = _newAngle;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to rotate a quad around its center, but when I run
I'm trying to make an iPhone app, but i found some issue that auto-rotate
I am trying to rotate an imagebutton to 360 by clicking itself but it
I'm trying to create a photo based app and I want to be able
My java app is trying to modify the following line from a file: static
I am trying to rotate a Sprite in three dimensions around its centerpoint, and
I'm currently trying to implement a rotate feature in my app wich is playing
So I've been toiling over this app trying to figure out this strange behaviour
I have a Rails app and trying to make a remote form, so far
I'm making a 'post text' app and trying to update my database with name

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.