My imageview consists of circle wheel as shown in below pic.I want that wheel should start rotating as soon as user presses a start button and stop rotating when user presses stop button.Is it possible programmatically?If yes,how can i do that?
Create a file named clockwise_rotation.xml and put it into /res/anim Change the duration according to your needs.
<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="3500"
android:fromDegrees="0"
android:interpolator="#android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:startOffset="0"
android:toDegrees="360"
/>
And make these two functions that you will be calling in your two buttons
private void startAnimation(){
Animation rotation = AnimationUtils.loadAnimation(getContext(), R.anim.clockwise_rotation);
mImageView.startAnimation(rotation);
}
private void stopAnimation(){
mImageView.clearAnimation();
}
Related
I wrote a rotation animation for a view which has 2 buttons in it, anim xml:
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:interpolator="#anim/linear_interpolator"
android:duration="10000"
android:repeatMode="restart"
android:repeatCount="infinite"
android:startOffset="0"
/>
The issue with this is that the location of the buttons seem to be fixed on the screen in the place where I put it in the XML, so when the buttons move clicking on them does nothing. I tried implementing rotation animation using RotateAnimation class but it was identical, buttons can only be clicked in the place where they were put in the XML, how to make the buttons actually movable?
I want to give a full rotation animation to my floating button, i have the code, but its only animating like rotating half. i want rotate the floating button from a position and it should end with the same position where it started( a full rotation ) , how to do that ?
here is my code , i want some one to modify the value or code
final OvershootInterpolator interpolator = new OvershootInterpolator();
ViewCompat.animate(fab).
rotation(170f).
withLayer().
setDuration(1000).
setInterpolator(interpolator).
start();
Make rotate.xml in res/anim:
<?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:repeatCount="0"
android:duration="1000" />
</set>
Then in code:
FloatingActionButton mFloatingButton = view.findViewById(R.id.myFloatingButton);
Animation mAnimation = AnimationUtils.loadAnimation(this, R.anim.rotate);
mFloatingButton.startAnimation(mAnimation);
I want to zoom an image automatically without touching the screen.
I.e. the image must be zoomed in as soon as the activity starts without any touch from the user.
Inside onCreate of MainActivity class you should define AnimationUtils and load the Animation on image view to whom you want to zoom Automatically.
Now make an xml class inside the anim and declare the xml inside load animation as second parameter.
this is the Java Class
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView image = (ImageView)findViewById(R.id.imageView);
Animation animation1 = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.zoom);
image.startAnimation(animation1);
}
}
This is the Anim xlm for zoom animation
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="0.5"
android:toXScale="3.0"
android:fromYScale="0.5"
android:toYScale="3.0"
android:duration="5000"
android:pivotX="50%"
android:pivotY="50%" >
</scale>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:startOffset="5000"
android:fromXScale="3.0"
android:toXScale="0.5"
android:fromYScale="3.0"
android:toYScale="0.5"
android:duration="5000"
android:pivotX="50%"
android:pivotY="50%" >
</scale>
</set>
Please visit this link. It will really help you. Just try to understand the whole program and you'll be able to achieve what you want. I just did! Don't call the zoomImageFromThumb method from any touch or click event. You can call it from any other event, such as you want to call at the activity startup, you can call it in onCreate method. It will work.
I have an animation when you click on the red button on the right(area 2). When you click on the button there starts no animation. When you click on a part in area 1 the animation starts.
I don't know what I do wrong. Anyone a solution?
Animation: rotate.xml
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="90"
android:pivotX="50%"
android:pivotY="50%"
android:duration="100"
android:fillAfter="true">
</rotate>
Java-code to start animation:
Animation animturn = AnimationUtils.loadAnimation(getContext(), R.anim.rotate);
v.setAnimation(animturn);
animturn.start();
Try with Invalidate() your View (v) after start() :
...
animturn.start();
v.Invalidate();
I have an animated rotating ImageButton.
<?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:repeatCount="infinite"
android:duration="2000" />
</set>
It starts when a user clicks it and runs an AsyncTask. Right now, after the AsyncTask reaches PostExecute, it jumps abruptly to its original state and stops.
Can I avoid that abrupt jump and just continue rotating until it reaches its original position and then have it stop there?
I'm using this to stop the animation at PostExecute right now:
refresh.getAnimation().cancel();
Thanks!
Turns out it was pretty simple.
I emailed the Catch Notes developer since this was inspired from their app.
refresh.getAnimation().setRepeatCount(0);
on PostExecute.