XScale vs XDelta in android animation - android

Am confused with XScale and XDelta
android:fromXDelta="0%p"
vs
android:fromXScale="1.0"
what are the core differences between them

XScale comes inside <scale> tag it is a resizing animation.
The below code is a slide down animation
<scale
android:duration="500"
android:fromXScale="1.0"
android:fromYScale="0.0"
android:toXScale="1.0"
android:toYScale="1.0" />
Where,
XDelta comes inside <translate> tag its is for vertical and/or horizontal motion its supports the following attributes in any of the following three formats: values from -100 to 100 ending with "%", indicating a percentage relative to itself; values from -100 to 100 ending in "%p", indicating a percentage relative to its parent; a float value with no suffix, indicating an absolute value.
The code below is a animation to move from origin to right
<translate
android:fromXDelta="0%p"
android:toXDelta="75%p"
android:duration="800" />

Related

View animation scale values relative to original

I wanted to make a basic animation on a TextView that would shrink when the user tapped it and then scaled back to the original size in order to provide visual feedback. Reading the docs, it seems that there are various ways to animate properties on Android, but I settled for using a view animation, defined in the following XML:
<set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="true" android:interpolator="#android:anim/accelerate_interpolator">
<scale
android:fromXScale="1.0"
android:toXScale="0.5"
android:fromYScale="1.0"
android:toYScale="0.5"
android:pivotX="50%"
android:pivotY="50%"
android:duration="100"/>
<scale
android:startOffset="100"
android:fromXScale="1.0"
android:toXScale="2.0"
android:fromYScale="1.0"
android:toYScale="2.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="50"/>
This works well enough, but it strikes me as odd that I have to calculate by how much I'm going to need to scale the second tag instead of being able to just use values relative to the original. Is there any way to use values relative to the original element (ie, using fromXscale="0.5" and toXscale="1.0") in the second tag?
If I get your question right try this
tv.animate().scaleXBy(2.0f).scaleYBy(2.0f).setDuration(100).setInterpolator(new LinearInterpolator()).start();
You can add reverse repeat policy or just add scale back animation.

Android XML Pulse Animation not working as expected

I am trying to code an animation that mimics a pulse animation that resembles this:
Concentrate on the inner blue circle (ignore the outer dark blue circle)
http://www.joedubs.com/wp-content/uploads/2016/01/breathe-now.gif
Here's what I managed to code so far:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<scale
android:duration="2000"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0.8"
android:toYScale="0.8" />
<scale
android:duration="2000"
android:fromXScale="0.8"
android:fromYScale="0.8"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="2000"
android:toXScale="1.8"
android:toYScale="1.8" />
<scale
android:duration="2000"
android:fromXScale="1.8"
android:fromYScale="1.8"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="2000"
android:toXScale="1"
android:toYScale="1" />
</set>
While this works for a certain extent, the animation skips and stutters when it repeats again. Can someone tweak it a bit to mimic a smooth pulse animation? (grow and reduce)
You can add a ObjectAnimator like this, creating a pulsating effect in the reverse mode:
ObjectAnimator scaleDown = ObjectAnimator.ofPropertyValuesHolder(ImageView,
PropertyValuesHolder.ofFloat("scaleX", 0.5f),
PropertyValuesHolder.ofFloat("scaleY", 0.5f));
scaleDown.setDuration(300);
scaleDown.setRepeatCount(ObjectAnimator.INFINITE);
scaleDown.setRepeatMode(ObjectAnimator.REVERSE);
scaleDown.start();
Another way to achive that is have a CustomClass and override your OnDraw method, creating a effect of growing or decrease increasing a variable and recalling invalidate(). I did these in another post to make my button background grow, if you want to follow this way it can be useful for you.
Pulsating Button Android

How to do a grow/reduce animation

I'm trying to make an image view to grow and reduce only on the x axis, yes, I want to deformate it.
It is actually the shadow of a bouncing ball. I'm trying to achive it with the scale animation, but it translate. Anyone that can help?
Here's the code of the animation that I'm using.
shadow.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_decelerate_interpolator" >
<scale
android:duration="10000"
android:fromXScale="1.1"
android:fromYScale="1.0"
android:toXScale="0.1"
android:toYScale="1.0" />
<alpha
android:duration="10000"
android:fromAlpha="1.0"
android:toAlpha="0.0" />
</set>
I tested your code out and here is what i found:
The code that you have provided initially scales the object in X axis to 1.1 directly(i.e without any animation).
Next, the object is scaled down in X axis to 0.1 while the alpha goes down. The scaling takes place about the upper left corner of the object(i.e the pivot is set to default).
If you want the scaling to happen about any other point,you can specify that as
android:pivotX="x%"
android:pivotY="y%"

Android: scale animation does not work when direction is changed

In my Android app, I hava a scale animation.
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="#android:anim/accelerate_interpolator" android:fillEnabled="true" android:fillAfter="true" >
<scale android:fromXScale="1.0" android:toXScale="0.0" android:fromYScale="1.0" android:toYScale="1.0" android:duration="32000" />
</set>
it works fine. it scales the view from left to right. but I need to scale from right to left. so when I modify the fromXScale="-1.0", the animation does not happen and the view is scaled instantly without animation.
My animation xml for the reverse direction is given below:
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="#android:anim/accelerate_interpolator" android:fillEnabled="true" android:fillAfter="true" >
<scale android:fromXScale="-1.0" android:toXScale="0.0" android:fromYScale="1.0" android:toYScale="1.0" android:duration="32000" />
</set>
How can I animate the View from reverse direction? what is wrong with my code?
You should also add a android:fillBefore="true" in your animation.
The in the forward animation your view usually will have a scale of 1 which mean you don't need to set it at start. But in the reverse animation you start at default (ie 1) and animate to... 1
using Pivot solved the problem. Its a better practice to control direction of an animation through pivotX and pivotY.

Zoom out Transition animation between two activities

I checked out the transition animation that comes with API code and i found animation zoom_enter and zoom_exit in which activity 1 sinks IN to show activity 2. I need the other way round. I need activity 2 to zoom out from inside and come on top. (I hope you are getting me). This type of animation is the same on iphone screen transition.
The code below is what i have for the effect that i don't need.
Here is the code for zoom_enter.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/decelerate_interpolator">
<scale android:fromXScale="2.0" android:toXScale="1.0"
android:fromYScale="2.0" android:toYScale="1.0"
android:pivotX="50%p" android:pivotY="50%p"
android:duration="#android:integer/config_mediumAnimTime" />
</set>
And here is the code for zoom_exit.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/decelerate_interpolator"
android:zAdjustment="top">
<scale android:fromXScale="1.0" android:toXScale=".5"
android:fromYScale="1.0" android:toYScale=".5"
android:pivotX="50%p" android:pivotY="50%p"
android:duration="#android:integer/config_mediumAnimTime" />
<alpha android:fromAlpha="1.0" android:toAlpha="0"
android:duration="#android:integer/config_mediumAnimTime"/>
</set>
Then right after startActivity i call the method below:
overridePendingTransition(R.anim.zoom_enter, R.anim.zoom_exit);
Can anyone suggest how i can make changes to the above files to have the screen transition i explained?
Try this in zoom_enter.xml and remove animations from zoom_exit.xml. You will see better effects.
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/decelerate_interpolator">
<scale android:fromXScale="0.0" android:toXScale="1.0"
android:fromYScale="0.0" android:toYScale="1.0"
android:pivotX="50%p" android:pivotY="50%p"
android:duration="#android:integer/config_mediumAnimTime" />
</set>
Hope this helps.
overridePendingTransition(zoom_enter_new, zoom_exit_actual);
First param is for the incoming Activity (so the new)
Second param is for the outgoing Activity (the actual)
So if you want to make the same effect of the video where seems that
the actual activity is hide instantly than second param need to be set to 0 (means no animation)
overridePendingTransition(zoom_enter_new, 0);
And for making the new activity zoomin like the video this is the anim xml resource explained (zoom_enter_new.xml in res/anim/ dir)
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_decelerate_interpolator">
<!--scale view fromX fromY are the starting point (.5 is 50% of scale, )-->
<!--scale view toX and toY are the final state (1 is 100%)-->
<!--pivot is the center of animation, so in your case the zoomin on the video is from the exact center (50% pivot x, 50% pivot Y)-->
<scale android:fromXScale=".5" android:toXScale="1"
android:fromYScale=".5" android:toYScale="1"
android:pivotX="50%p" android:pivotY="50%p"
android:duration="#android:integer/config_longAnimTime" />
<!-- alpha animation is made at the same time of scale animation, and for me make a better and smooth result, alpha 0 is full trasparent, 1 is the normal state. The final alpha state of the activity after this animation is 1, so pay attention toAlpha must be 1 if you don't want glitch-->
<alpha android:fromAlpha="0.5" android:toAlpha="1"
android:duration="#android:integer/config_longAnimTime"/>
</set>
overridePendingTransition(R.anim.zoom_enter_new, 0);
Tobia

Categories

Resources