I am adding a infinite animation to my ImageView.
Below is my animation code:
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="70%"
android:pivotY="70%"
android:repeatCount="infinite"
android:startOffset="2000"
android:repeatMode="reverse"
android:toXScale="0.8"
android:toYScale="0.8" />
and java code is:
Animation pulse = AnimationUtils.loadAnimation(this, R.anim.pulse);
reviewImage.startAnimation(pulse);
the problem is that it make delay after each animation like expand+delay+collapse+delay both i want to give delay only after one cycle means after expand+collapse+delay
You cannot do that with one animation, because the way it works is that it performs animation and will delay the next animation by 2000ms (as specified in xml). From framework's point of view those animations are not connected to each other and it cannot assess them as one animation, so those are two separate animations.
You have to create 2 animations and play them sequentially.
See here how to do that with AnimatorSets, but you may as well do it with xml.
<set>
<scale
android:duration="500"
.../>
<scale
android:startOffset="500"
.../>
</set>
Related
Does anybody has an example of animation that looks like tilting slightly on left and right but middle is not moving. It looks like when you want to move icons on iOS and make a long press you could see that kind of animation what I need. I got animation but it more looks like moving the whole item instead of tilting. Here is my code
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:duration="70"
android:interpolator="#android:anim/linear_interpolator"
android:pivotX="40%"
android:pivotY="40%"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:toDegrees="1" />
<translate
android:duration="70"
android:fromXDelta="-3"
android:fromYDelta="3"
android:interpolator="#android:anim/linear_interpolator"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:toXDelta="0.1" />
</set>
Its like wiggling effect on this screen
The rotation effect can be made by adding 2 parameters
android:fromDegrees="0"
android:toDegrees="3"
I'm trying to apply a scaling animation to my list. The idea is that the list collapses to the top, the way I'm doing it is by scaling the Y-axis to nothing. The animation is not being applied correctly however - the list just disappears for the duration listed in the XML file with no interpolation animation, then reappears when the duration has finished. This happens regardless of what fillAfter is set to (which should be true, right?).
Why is this not interpolating correctly, and why it is reappearing again after the animation terminates?
The anim file:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:interpolator="#android:anim/accelerate_interpolator"
android:fromYScale="1.0"
android:toYScale="0.0"
android:duration="500"
android:pivotY="0"
android:fillAfter="true"
/>
</set>
How I call the animation:
ListView list = (ListView) getView().findViewById(android.R.id.list);
Animation collapseList = AnimationUtils.loadAnimation(getActivity(), R.anim.collapse_search_results);
list.startAnimation(collapseList);
Okay, I fixed this by adding pivotX, fromXScale and toXScale values to my XML file. I needed them even though I'm not scaling along the X-axis.
The animation still does not persist however, but I wanted to get rid of the fragment hosting the ListView anyway so I just added a listener to destroy the fragment when the animation has finished.
My working XML file:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:interpolator="#android:anim/accelerate_interpolator"
android:fromYScale="1.0"
android:toYScale="0.0"
android:fromXScale="1.0"
android:toXScale="1.0"
android:duration="400"
android:pivotY="0"
android:pivotX="0"
android:fillAfter="false"
/>
</set>
I am using animation for item click of GridView.
My animation file is expand_then_contract.xml as below
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<scale
android:duration="500"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.1"
android:toYScale="1.1" />
<scale
android:duration="500"
android:fromXScale="1.1"
android:fromYScale="1.1"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="500"
android:toXScale="1"
android:toYScale="1" />
</set>
And I'm applying it in the onItemClickListener of GridView as below
onItemClick(... View view ..)
{
Animation expand_contract = AnimationUtils.loadAnimation(this,
R.anim.expand_then_contract);
view.bringToFront();
view.clearAnimation();
view.setAnimation(expand_contract);
view.startAnimation(expand_contract);
}
It is working as expected. But it gets stuck in between. At some point when it is contracting back to normal position, for a moment it freezes. Why does this happen. Why can't animation in my code work as smoothly as they make it in GoLauncher Animations. Do they use any external libraries.
The problem is with interpolator , your job is done in two diffrent steps
So , Better you merge them both in one step or Use linear interpolator so that there is no halt between executoion
I am trying to start an animation AFTER 1 second. I have used the attribute "android:startOffset" in my XML file, but it does not work completely the way I expected. I was expecting the view to NOT EVEN BE DRAW in its initial position (that is, the position set in the attributes "fromXDelta" and "fromYDelta") before the offset I set has passed. Here is my XML:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:ordering="sequentially"
android:shareInterpolator="false" >
<translate
android:duration="2000"
android:startOffset="1000"
android:fromXDelta="-70%p"
android:fromYDelta="0%p"
android:interpolator="#android:anim/linear_interpolator"
android:toXDelta="+0%p"
android:toYDelta="0%p" />
</set>
If I try to move my view using the above animation, the view is drawn IMMEDIATELY at the position -70% of the screen. Then the one second passes and then, as expected, the animation kicks in and starts to move the view. However, I DO NOT want the view to be drawn at all before that 1 second!. How can I achieve this?
Thank you in advance.
UPDATE
I am calling the above XML just after a startActivity call (the *R.anim.animation_coming_in* below), like this:
startActivity(new Intent(this, ThankYouActivity.class));
overridePendingTransition(R.anim.animation_coming_in, R.anim.animation_coming_out);
You could try using a pair of alpha animations with very short duration so that the view is hidden until it's needed. Something like this:
<set ...>
<alpha
android:fromAlpha="0.0"
android:toAlpha="0.0"
android:duration="1"
android:startOffset="0" />
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="1"
android:startOffset="1000" />
<translate
...
/>
</set>
Alternatively, you could implement this set of animations in code. Doing so would enable you to use a Handler to start the animation after a delay so that the view is hidden until the animation starts.
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.