qwertz
qwertz

Reputation: 6286

Android translate animation move to absolute position

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" />

Upvotes: 0

Views: 3507

Answers (1)

mikeD
mikeD

Reputation: 481

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.

Upvotes: 5

Related Questions