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.
Related
I try to achieve an animation like this one :
The code of my animation look like this :
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromDegrees="0"
android:interpolator="#android:anim/accelerate_decelerate_interpolator"
android:pivotX="100%"
android:pivotY="100%"
android:repeatCount="infinite"
android:repeatMode="restart"
android:toDegrees="360"
>
</rotate>
and the result :
it's not that bad, but as you can see, every time the animation ends there is a small pause before the next start so I can't reach the same result as seen in the first gif. And I don't really know what I can modify to achieve that. With a linear_interpolator it's working but there is no accelerate/decelerate anymore.
Any idea ?
If I have infinite animation in activity and navigate away from activity, does it causes memory leak? Do I have to stop animation explicitly or is it somehow managed on framework level? What I mean by infinite animation:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false"
android:repeatCount="infinite">
<rotate
android:duration="1000"
android:interpolator="#android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="restart"
android:toDegrees="360" />
From developers webpage :
You should usually use the onPause() callback to:
Stop animations or other ongoing actions that could consume CPU.
Source : http://developer.android.com/training/basics/activity-lifecycle/pausing.html#Pause
Not closely related, but If the leak is caused by the Animator class, e.g. holding a reference to an Activity/Fragment, you should call animatorInstance.removeAllListeners() in your fragment/activity onDestroy callback.
I made a background to animate from left to right. Everything works fine but when background-image reaches right, the animation starts over again.
How can i make it to run continuously so that it appears it is traveling from left to right always (no breaks)?
Use this:
<?xml version="1.0" encoding="utf-8"?>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="15000"
android:fromXDelta="-95%p"
android:repeatCount="infinite"
android:repeatMode="restart"
android:toXDelta="-100%p" />
I am trying to implement the Flip card transition effect between two activities in my app by taking help from :
http://blog.robert-heim.de/karriere/android-startactivity-rotate-3d-animation-activityswitcher/.But I couldn't understand what areActivitySwitcher.java and Roatate3dAnimation.java in the above mentioned site. I have two activities in my app between whom I want to show this transition effect. They are MainActivity.java and About_us.java.Please explain the code with reference to my activities. I also searched on http://developer.android.com/training/animation/cardflip.html but in vain as it not for activities.
Thanks!
Disclaimer: This is not a an actual 3D Animation Flip. This merely imitates it, though some don't agree. Give it a try and if you like it, great! If you don't, my apologies.
In my early days of learning to code, I was having issues implementing a proper 3D Animation flip, so I went with this, it simulated it enough to satisfy my needs, but to each her/his own. To do what I did, first make sure that you have a folder called anim under your res folder for your project. Then you will need to create two xml files (I have mine called from_middle and to_middle). Below is the code for each of those:
from_middle.xml:
<?xml version="1.0" encoding="utf-8"?>
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="0.0" android:toXScale="1.0"
android:pivotX="50%"
android:fromYScale="1.0" android:toYScale="1.0"
android:pivotY="50%"
android:duration="500" />
to_middle.xml:
<?xml version="1.0" encoding="utf-8"?>
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="1.0" android:toXScale="0.0"
android:pivotX="50%"
android:fromYScale="1.0" android:toYScale="1.0"
android:pivotY="50%"
android:duration="500" />
After those are created, all you need is one line of code to run this animation, which you should be placed after you start your next activity:
overridePendingTransition(R.anim.from_middle, R.anim.to_middle);
Done! Now run it!
Based on user1672053's answer, you need to add a start offset to the from_middle.xml resource which is equal to the duration of the to_middle.xml animation resource.
I've a simple view animation, but I can't see to get "rid" of the animation "unwinding" (and I can't seem to find a solution online).
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/linear_interpolator"
android:shareInterpolator="true" >
<scale
android:duration="250"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="0"
android:toXScale="1.1"
android:toYScale="1.1" />
</set>
What this does is, simply, inflates the View by 10% proportionally, from the middle.
But, when it executes, it inflates and, when it reaches the end, it deflates back. I want to avoid that -- the "unwinding" effect -- when it scales back from 110% to 100%.
How can that be done?
Edit:
I'm starting it simply with this:
Animation animation1 = AnimationUtils.loadAnimation(this, R.anim.<name>);
v.startAnimation(animation1);
The correct answer is found here: How can I animate a view in Android and have it stay in the new position/size?
It is putting this:
android:fillAfter="true"
android:fillEnabled="true"
inside the <set tag.