I want to rotate an Image in a slow way on Android. I can do this by creating a Bitmap and by the help of of Matrix class. But i don't know how to make it slow, like it should take 3 seconds to rotate.
            Asked
            
        
        
            Active
            
        
            Viewed 1,416 times
        
    1
            
            
        - 
                    1Please read [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask) – Chris Pickford Jun 16 '16 at 08:28
- 
                    Your question is not clear please . By rotation what you mean animation or tilting of image – Hitesh Sahu Jun 16 '16 at 08:36
3 Answers
1
            Rotate
Rotate animation uses  tag. For rotate animation required tags are android:fromDegrees and android:toDegrees which defines rotation angles.
Clock wise – use positive toDegrees value
Anti clock wise – use negative toDegrees value
rotate.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <rotate android:fromDegrees="0"
        android:toDegrees="360"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="600"
        android:repeatMode="restart"
        android:repeatCount="infinite"
        android:interpolator="@android:anim/cycle_interpolator"/>
</set>
Save in anim folder
public class AnimationActivity extends Activity{
    ImageView img;
    Animation rotate;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fadein);
        img = (ImageView) findViewById(R.id.myimageid);
        // load the animation
        rotate = AnimationUtils.loadAnimation(getApplicationContext(),
                R.anim.rotate);
        img.startAnimation(rotate);
    }
}
 
    
    
        Sohail Zahid
        
- 8,099
- 2
- 25
- 41
1
            
            
        In Kotlin you can use the ObjectAnimator do this super easily. For example:
ObjectAnimator.ofFloat(view, "rotationX", 180f).apply {
duration = 2000
start()
}
- view: the view you want to rotate
- "rotationX": the propertyName you want to alter.
 "rotationX" gives you rotation into and out of the screen
 "rotationY" gives you clockwise/counterclockwise rotation
- 180f: how many degrees you want to rotate the view
- duration: the number of milliseconds the animation should take to complete
 
    
    
        Code on the Rocks
        
- 11,488
- 3
- 53
- 61
0
            
            
        You can use rotate animation to achieve this.
Create anim folder under res directoy inside that place this xml.
rotate_around_center_point.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >
    <rotate
        android:duration="2500"
        android:interpolator="@android:anim/linear_interpolator"
        android:pivotX="50%"
        android:pivotY="50%"
        android:repeatCount="infinite"
        android:repeatMode="restart"
        android:toDegrees="360" />
</set>
Set animation to view like this.
ImageView animationTarget = (ImageView) this.findViewById(R.id.testImage);
Animation animation = AnimationUtils.loadAnimation(this, R.anim.rotate_around_center_point);
animationTarget.startAnimation(animation);
 
    
    
        Kumar M
        
- 994
- 6
- 21
 
    