hi i have 2 views that i want to have zig zag up and off the screen. ive tried using object animators like this
float 1
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/decelerate_interpolator"
android:ordering="sequentially" >
<objectAnimator
android:duration="6000"
android:propertyName="y"
android:repeatCount="0"
android:valueFrom="1500"
android:valueTo="-1000"
android:valueType="floatType" />
</set>
and float 2
<objectAnimator
android:duration="3000"
android:propertyName="x"
android:repeatCount="1"
android:repeatMode="reverse"
android:valueFrom="-250"
android:valueType="floatType"
android:valueTo="50" />
<set
android:duration="3000"
android:propertyName="x"
android:repeatCount="1"
android:repeatMode="reverse"
android:valueFrom="-250"
android:valueTo="50"
android:valueType="floatType" />
</set>
but the results are varied, ie works on tablets but not smaller screens,
I've changed the code to do this programmatically and all it does is slightly change the way I goes up the screen all I want is both balloons to go up the screen at the moment it works beautifully on my tablet but on smaller screens it only shows one balloon. Been struggling on this a while now all views are laid out in XML and are hidden until needed I found there was a way of using fractions in my from and to values but apparently its deprecated any suggestions for a total n00b like me?
Have you tried creating your own custom interpolator, it basically defines how your animation is going to behave with respect to time, for example accelerate interpolator when used with lets say translate animation, it will accelerate your view, so you might have to create a custom interpolator, that will define your zig zag path, along with translate animation. you can read from here :
Tutorial on Interpolators
Related
How to mention the pivot point for the scale animation in the below xml file. How to specify the pivot being the left edge, right edge and the centre (the default)
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/linear_interpolator"
android:propertyName="scaleX"
android:valueType="floatType"
android:duration="500"
android:valueTo="0"/>
UPDATE:
the I tried the following and it isn't working
android:pivotX="1.0"
As per this link it seems this is currently not possible. As suggested in the page we will have to set the transformPivotX property of layout we are animating.
I have a transition from one activity to another that I am using in overridePendingTransition. Unfortunately all overridePendingTransition uses is the resource id of the file, so I am having trouble about how to edit this file so my transitions are proper.
Basically what I need to do is make changes to the R.anim.flip_in_scale_in so that I can change the value of the transitions fromX/toX so that it is set based on the user's screen size.
overridePendingTransition(R.anim.flip_in_scale_in, R.anim.stationary_item);
How do I update the R.anim.flip_in_scale_in file before use in the overridePendingTransition?
There isn't a way you can alter the animation from the resource file in the way you want.
However, you CAN create the animation to use percentages rather than dp values. When the animation is applied to the Activity's View, it will animate entirely on the view's size (which in most cases is the screen size).
This for example:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="100%"
android:toXDelta="0%"
android:duration="500"
/>
</set>
Will slide in the view from the right side to the screen within half-a-second.
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:interpolator="#android:anim/accelerate_decelerate_interpolator"
android:fromXScale="1.0"
android:toXScale="1.4"
android:fromYScale="1.0"
android:toYScale="1.4"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000" />
</set>
This will increase the view to 40% it's current size over the span of one second. The pivot will be directly in the middle of the view regardless of the view's size.
I've had trouble finding good documentation about animations in Android, but I managed to get my animation working. What I'm concerned about the way I did it is efficiency/performance.
My goal was to have a cloud image move across the screen over and over and repeat forever. To do this I ended up putting 2 identical ImageViews positioned over each other and defining 2 animations:
cloud_slide_exit.xml:
<translate
android:fromYDelta="0"
android:toXDelta="-100%p"
android:duration="25000"
android:repeatCount="infinite"
android:repeatMode="restart"
/>
cloud_slide_enter.xml:
<translate
android:fromYDelta="0"
android:fromXDelta="100%p"
android:duration="25000"
android:repeatCount="infinite"
android:repeatMode="restart"
/>
I applied the first animation to "image1" and the second to "image2." The first animation moves "image1" from right (on-screen) to left (off-screen) while the second animation moves "image2" (which starts off screen) from right (off-screen) to left (on-screen). The end result when you view both animations is that the image moves across the screen. When it reaches the left end of the screen it will start coming from the right side of the screen. This is the only way I could think of doing this.
Is there a more efficient way to go about doing this animation? I'd like to find a more efficient way because I actually have 3 clouds moving which means that I have 6 ImageViews/TranslateAnimations.
replace your code by following code:
cloud_slide_exit.xml:
<translate
android:fromXDelta="100%p"
android:toXDelta="0%p"
android:duration="25000"
android:repeatCount="infinite"
android:repeatMode="restart"
/>
cloud_slide_enter.xml:
<translate
android:fromXDelta="100%p"
android:toXDelta="0%p"
android:duration="25000"
android:repeatCount="infinite"
android:repeatMode="restart"
/>
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
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/