How to animate button in android with flip effect? - android

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.

Related

How to make shaking animation on android like iOS has?

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"

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 create FAB reveal animation like Google keep and Inbox by gmail

I am trying to create FAB animations like shown in Google design guidelines such as circular reveal, morph animations (google keep and inbox) in API Level 15. I used google design support library to add FAB icon to my app.
I would appreciate your help in this regard. Thanks.
The FAB animation is actually a simple scale animation that you can write yourself, something like this:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/linear_interpolator">
<scale
android:fromXScale="0.0"
android:toXScale="1.0"
android:fromYScale="0.0"
android:toYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="250" />
</set>
That goes in an xml in the "anim" folder.
And then you animate the button in the java code:
final Animation mAnimation = AnimationUtils.loadAnimation(context, R.anim.animation_name);
yourFab.setVisibility(View.VISIBLE); //It has to be invisible before here
yourFab.startAnimation(mAnimation);

Animation loop in android

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" />

Flip card transition between two activities Android

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.

Categories

Resources