Android fade out animation using Cosine function - android

I in my Android Honeycomb application there is a View which has a fade in and fade out animation. Here's most part of the animation code:
<scale
android:fromXScale="1.0"
android:toXScale="1.0"
android:fromYScale="1.0"
android:toYScale="0.0"
android:pivotX="0%"
android:pivotY="0%"
android:duration="500" />
The way it's working right now the animation happens in a linear time but I want to do it according the Cosine function, that is from Cos(0) until Cos(0,5*pi) the fade out case.
Is it possible to do such thing?
Thank you.

You are free to create your own Interpolator. (See the interface description here.) This can then be applied with Animation.setInterpolator(Interpolator). Or, see this discussion for ways of applying custom Interpolators in XML.

If you don't want linear interpolation, you have choice between:
AccelerateDecelerateInterpolator, AccelerateInterpolator,
AnticipateInterpolator, AnticipateOvershootInterpolator,
BounceInterpolator, CycleInterpolator, DecelerateInterpolator,
LinearInterpolator, OvershootInterpolator
http://developer.android.com/reference/android/view/animation/Interpolator.html
So maybe what is the closest to a Cosine is:
AccelerateDecelerateInterpolator
An interpolator where the rate of change starts and ends slowly but
accelerates through the middle.

Related

Android triangle fadein animation

I have the following animation:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="100%" android:toYDelta="0%" android:duration="1000" />
<translate android:fromXDelta="80%" android:toXDelta="0%" android:duration="1000" />
</set>
I use this to animate a new view to is showing up. This animation run from bottom to top and from right to left, but the animation is like rectangle. And i wana make it to be like a triangle
In other words i want the two points (X and Y) that makes the animation to be linked by a straight line.
(Not enough rep to comment)
Is it important for it to be clickable as a triangle? What I mean is, couldn't you just load on the view a triangle-like Drawable image(there are many free icon packs around or you can create your own as .png)?
This way you SEE the triangle, while as an object is just a rectangle with a texture of a triangle. (As I don't think there is any implementation in AndroidSDK of a TriangularView, but I might be wrong!).
Another way is to use a shape drawable resource.
An easy example is how it was done by Sanket Kachhela in this post
https://stackoverflow.com/a/22043386/4482734
You could take it as a starting point.
Then again, much of this post was based on the idea you needed to interact with the Triangle, but I could be wrong and it has no meaning to do so.

How do I animate, Moving an ImageView on a circular path with certain radius in android?

Please Find the attachment for my image.
https://docs.google.com/file/d/0B_c-SDSO63obS0ZyQ1dsOXdUQmc/edit?usp=sharing
My task is, animate that GONG type of image up to some time with clock wise and anti clock wise.
For that i did some coding in animation but i didn't succeed. I am using both translate and rotate.
<translate
android:fromXDelta="0%p"
android:toXDelta="75%p"
android:duration="1500" />
and rotate functions,
<rotate android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="600"
android:repeatMode="restart"
android:repeatCount="infinite"
android:interpolator="#android:anim/cycle_interpolator"/>
Actually my idea is in a specific time i want to move with specific angle. But i don't know the correct way to solve this task.
Please help me. sorry for my English.
All answers are acceptable
Thanks
Shankar
You have divided a circle in 12 parts in that image and that equals to 30 degrees per segment.
you have to rotate it like this to look proper
rotateDegree=[steps]*30;
use AlarmManager to trigger animation in specific time
EDIT:
to move your image in circular path with a radius you have to give a different pivot x and y
you can find it by tryng with
pivotX= 0 and pivotY=(negative value)
I hope this helps.

Android Flip Animation Grow and fade in from around , shrink and fade out to around?

I want to make a flip animation where one image will grow from around and it will shrink to one point. During growing it will be fade in and when shrink it will be fade out. I have tried many xml code but exactly this kind of code still unavailable to me.
For example, here is an example of what I've tried. It is growing from around but not fading in.
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/linear_interpolator"
android:fromXScale="1.4"
android:toXScale="0.0"
android:fromYScale="1.4"
android:toYScale="0.0"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="false"
android:duration="1000"
/>
You can use 2 animation sets for that.
Animation set 1 will be for Scaling up and Fade in.
After animationSet1 is ended, start animation set 2
Animation set 2 will be for Shrinking and Fade out.

Showing both sides of a coin being flipped using Android standard animation

I'm very close to getting a "coin flipping" animation to work, but due to the limitations (bugs?) in the current Animation system - I cannot find a way to show BOTH sides of a coin flipping in the air.
For example, I have the following Animation .XML:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<scale
android:repeatCount="17"
android:repeatMode="reverse"
android:interpolator="#android:anim/accelerate_decelerate_interpolator"
android:fromXScale="1.0" android:toXScale="1.0"
android:fromYScale="1.0" android:toYScale="0.0"
android:pivotX="50%" android:pivotY="50%"
android:fillEnabled="true"
android:fillAfter="true"
android:duration="60"
/>
<scale
android:repeatCount="1"
android:repeatMode="reverse"
android:interpolator="#android:anim/accelerate_decelerate_interpolator"
android:fromXScale="1.0" android:toXScale="2.0"
android:fromYScale="1.0" android:toYScale="2.0"
android:pivotX="50%" android:pivotY="50%"
android:fillEnabled="true"
android:fillAfter="true"
android:duration="800"
/>
<translate
android:repeatCount="1"
android:repeatMode="reverse"
android:interpolator="#android:anim/accelerate_decelerate_interpolator"
android:fromXDelta="0%"
android:toXDelta="0%"
android:fromYDelta="0%"
android:toYDelta="-150%"
android:fillEnabled="true"
android:fillAfter="true"
android:duration="800"
/>
</set>
This "fakes" a flipping animation by scaling the coin on the Y-axis and reversing it on a loop. In combination to this, there's a scale to make the overall animation bigger, while also translating it up and down. But it is only ever gonna show the one side of the coin.
I tried having two of these animations, each side of the coin, running at the same time, but I cannot find a way to stagger them due to the REPEATCOUNT not working when applied to an AnimationSet. Otherwise I could introduce some kind of delay after one anim (and before the other one) so they alternate, giving the illusion of a coin flipping.
Does anyone know any way I can tweak this to get the desired result?
I had thought of giving up and doing a frame-based anim (pre-render the flip as frames), but it appears you can't mix Frame & Tween anims, so I'd lose the flip "height" and "distance" effects.
(I have another issue when it comes to the coin landing - e.g. the final result is random, but I'm hoping I can switch in the actual result at the end?)
Thanks in advance!
I recently wanted to implement something like this for a project. I finally came up with a solution and the result was good enough. Hope it helps someone else who is trying to achieve the same animation.
I uploaded the result as a gist on GitHub.
For a preview of the animation click here.
For the full android studio project visit our CoinToss repository.
I was looking for something like this myself, even with the scaling of the image so it appears the imageview is getting closer to the screen.
I combined your animation with this solution to do exactly what you wanted and its fairly lightweight, missing out the need for multiple views.
https://github.com/Lojko/Booty/blob/master/src/game/booty/BootyGameActivity.java
Changed Location of the Original Link: http://www.jasoncavett.com/2011/05/changing-images-during-an-android-animation/#comments
See the FlipCoin class and how its used, I have an animation already existing (created in the same way as detailed by the link)
This code shows the same procedure
http://www.inter-fuser.com/2009/08/android-animations-3d-flip.html

Rotate button about X-axis in an Android app

I want to rotate a button about X-axis when clicked and then display a different image so it creates an effect that after button click it's flipping and showing a different image which is at its backside.
I'm using following xml for rotation of button:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<set android:interpolator="#android:anim/decelerate_interpolator">
<rotate
android:fromDegrees="0"
android:toDegrees="-360"
android:pivotX="25%"
android:pivotY="25%"
android:fromXDelta="0"
android:toXDelta="0"
android:fromYDelta="0"
android:toYDelta="0"
android:duration="400" />
</set>
</set>
But it's rotating the button in 2-D plane about the button's center.
I have a flip example here:
http://www.inter-fuser.com/2009/08/android-animations-3d-flip.html
I'm afraid the conventional graphics and animation APIs are 2D. To use that 3rd dimension you'd need to look into OpenGL, which is non-trivial.
You might be able to fake a depth effect by writing a custom animation that uses setPolyToPoly to warp your initial rect into a trapezoid.
It's been a while since this question is posted, but just for the record - there is a way in newer versions of android, and for back compatibility use http://nineoldandroids.com/

Categories

Resources