How to make shaking animation on android like iOS has? - android

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"

Related

Give a delay after repeat animation

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>

How can i animate hamburger drawer icon

I have to animate a drawer icon. The red circle needs to pop up in the same way as in the gif below. Any of the animation styles are fine, I only want to know if I can create an animation like these. Any thoughts?
I have searched the internet, but I haven't found anything so far.
You could try using the scale animation, for example, to get a similar effect of the pop animation in that gif you could do the following:
Create a file res/anim/bounce.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/bounce_interpolator">
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="800"
android:fromXScale="1.5"
android:fromYScale="1.5"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1"
android:toYScale="1" />
</set>
And then load the animation:
Animation bounceAnimation = AnimationUtils.loadAnimation(getActivity(), R.anim.bounce);
yourView.startAnimation(bounceAnimation);

How to animate button in android with flip effect?

I want to animate a button in android just like flip a board, one side is black and another side is green.
I can see some answer just like a rotate effect but it's not like a flip effect. I don't want to do such simple take with OpenGL.
Below shake.xml doesn't work for me:
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="100"
android:fromDegrees="-5"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="10"
android:repeatMode="reverse"
android:toDegrees="5" />
You can use like view.animate()...(here set your animation).setDuration(100).start();
But it need api larger than 13.

Avoid animation automatically "unwinding"?

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.

android animation starting new activities or dismissing an Activity

Is there a tutorial or a code example of various kinds of View Animations available in Android. Basically what I am trying to do is say if start a new Activity, I am trying to get that activity start out like zoom in till it fills the screen or Fade out when I am going to finish the activity. Is there a way i can do this ?
Any help will be greatly appreciated.
Thanks
-Chandu
So you need to use OverridePendingTransition from the activity: http://developer.android.com/reference/android/app/Activity.html
Some examples with Fade in/out can be found here: http://www.anddev.org/novice-tutorials-f8/splash-fade-activity-animations-overridependingtransition-t9464.html
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/decelerate_interpolator"
android:zAdjustment="top"
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="1000" />
Zoom:
<scale
android:pivotX="50%"
android:pivotY="50%"
android:fromXScale=".1"
android:fromYScale=".1"
android:toXScale="1.0"
android:toYScale="1.0"
android:duration="2000" />

Categories

Resources