scale animation in Fragment Transition - android

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.

Related

Android Animations - Animate view to a specific position

I have a load screen/pop up screen which is a fragment which shows up whenever I call an API. I like how it looks currently, but I would like to liven it up by adding a bunch of animations to the views in the load screen.
I am using the property animation framework to good effect for
scaling and changing the alpha value(transparency) of views in their current positions.
I am now trying to get a view to animate(translate + alpha change) to it's current position in the static screen. I do not however, wish to hardcode values since this would clearly mess up the alignment of views and cause overlaps and other problems.
How do I translate a view from some point outside the screen, to it's current position in the static screen? Eg: In my static screen if I have a view that is centre aligned in the parent layout, how do I animate the view from a position outside the screen to this current position. I have tried the following but it does not work since it expects float values.
<set android:ordering="together">
<objectAnimator
android:duration="1500"
android:propertyName="y"
android:valueFrom="0"
android:valueTo="50%p"
android:valueType="floatType" />
<objectAnimator
android:duration="1500"
android:propertyName="alpha"
android:valueFrom="0"
android:valueTo="1"
android:valueType="floatType" />
</set>
I am trying to keep as much of the animation logic in xmls as possible.
After a little more research I came across the translationY(and translation X) attribute which seems to be the one I was looking for.

Android Translation animation

i am trying to animate an image view by ensuring that the object appears in the center of the screen and then translates up.. to its final position. the code i used is as follows.
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:fromYDelta="400"
android:toYDelta="0"
android:duration="800"/>
</set>
This code works when u have a device of 4.7"(galaxy s3) screen size the image will appear at the center of the screen and then move to its set position. But on a screen of 4" (S advance or htc desire x) the image practically appears at the screen bottom.
So is there any way to ensure that the image is at the center of the screen heedless of the device on which the code is running?? Thanks in advance..
Use percentages instead of values to make the Animation uniform across all screen sizes.
The animation should apply its transformation after it ends
android:fillAfter="true"
The animation begins from the vertical center, i.e 50% of Y
android:fromYDelta="50%p"
The animation ends at the top, i.e. 0% of Y
android:toYDelta="0%p"
XML:
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="800"
android:fillAfter="true"
android:fromYDelta="50%p"
android:toYDelta="0%p" />
</set>
thanks for ur response..
i tried ur suggestion 's and i found that using 50%p to then in a 4 inch screen the image view is present at around 3\4of the screen. but when i use 25%p then its around the center. in case of s advance its center and in s3 its relatively center.. i guess it depends on the size of the image.(dimention)

how to make a view zigzag up the screen?

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

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 - Alter animation in resource file

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.

Categories

Resources