android - How can i use RotateAnimation to rotate a circle? -


I want my circle image so that the user rotates in the form of a touch and drag it. If the user leaves it to the right, then he should spin right and vice versa. As you spin a DJ disk, if you know what I mean. I played a bit with ottaichlich and rotate animation, but I am not going anywhere.

Any thoughts?

Assume that you have ImageView mCircle , which you will rotate. Rotate it to RotateAnimation will use OnTouch method angle where the user determines the finger Example

, following its main activity Work

  private imageView mCircle Private double mCurrAngle = 0; Private Double Empress Angle = 0; Override public null on @reate (bundle saved instainstate) {super.naught (savedinstenstate); SetContentView (R.layout.main); MCircle = (ImageView) FindViewById (R.id.circle); MCircle.setOnTouchListener (this); // Your activity should apply onTouchListener} @Override Public Boolean onTouch (see V, MotionEvent event) {last name XC = mCircle.getWidth () / 2; Last float yc = mCircle.getHeight () / 2; Last float x = event .getX (); Last float y = event .getY (); Switch (event.getAction ()) {Case MotionEvent.ACTION_DOWN: {mCircle.clearAnimation (); MCurrAngle = Math.toDegrees (Math.atan2 (x - xc, yc-y)); break; } MotionEvent.ACTION_MOVE case: {mPrevAngle = mCurrAngle; MCurrAngle = Math.toDegrees (Math.atan2 (x - xc, yc-y)); Animate (Ampravenggal, M. Cruel Angle, 0); break; } MotionEvent.ACTION_UP case: {mPrevAngle = mCurrAngle = 0; break; True} true; } Private void animate (double fromDegrees, double toDegrees, DurationMillis long) {final RotateAnimation rotate = new RotateAnimation ((float) fromDegrees, (boat) toDegrees, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f); Rotate.setDuration (durationMillis); Rotate.setFillEnabled (true); Rotate.setFillAfter (true); MCircle.startAnimation; }  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -