Android translate animation move to absolute position - android

is there a way to tell a translate animation to always move to a absolute position, instead to a position relative to the card. As far as I know, using android:toXDelta only moves it to a relative position. I want it to move to a absolute position (lets say width of the screen / 2 and height of the screen / 2) from every point on the screen.
My animation:
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_decelerate_interpolator"
android:duration="1000"
android:fromXDelta="0"
android:fromYDelta="0"
android:toXDelta="-20%p"
android:toYDelta="-20%p" />

Judging from official Documentation it is not possible from XML.
However, you can do this in your Java code. Example:
view.animate().translationX(0f).translationY(0f).setInterpolator(new AccelerateDecelerateInterpolator()).start();
TranslationX and TranslationY animates to an absolute position. There is also TranslationXBy an TranslationYBy that animate relatively.

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 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.

scale animation in Fragment Transition

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.

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)

Animations to make things go around the screen (Android)

I'm new to Android developing. I want some animations when clicking on the card and it will move around the screen and stay at its new position forever (its interactive area should change too).
At first the card is located at the center-bottom of the screen (XDelta= 50% YDelta = 70%) then it will move up straight to center of the screen (XDelta =50% and YDelta is 40%). Then it will move to its upper left (10 dp from the left of the screen and 10 dp from the top of the screen) Sorry I can't post images due to my lack of reputation.
And here's my code in res/anim/card1.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="200"
android:fromXDelta="50%"
android:fromYDelta="70%"
android:toYDelta="40%"
android:toXDelta="50%"
android:fillEnabled="true"/>
<translate
android:duration="100"
android:fillEnabled="true"
android:fromXDelta="50%"
android:fromYDelta="40%"
android:startOffset="200"
android:toXDelta="10"
android:toYDelta="10" />
</set>
And code to get it work when clicking on the card
Animation anim = AnimationUtils.loadAnimation(MainActivity.this,
R.anim.card1);
iv_card.startAnimation(anim);
... but it just don't animate the way I want. Please help me!!!!
Check Out this (http://www.tktutorials.com/2013/07/animation-in-android-using-xml-files.html) this may help your need. Alter the translate.xml file as per your need, which is located in Res->anim->translate.xml
And solution for your posting Image. My suggestion is upload your pic in googleDrive, then change the share setting for the particular pic from private to Public on web and use the url Link to your question.

Categories

Resources