Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How a Translate Animation works: Android

I'm trying to move a RelativeLayout using TranslateAnimation. Code I have written for performing the same is:

translateAnimation = new TranslateAnimation(0, 0, heightOfRootView-excuseContainer.getHeight(), currentYPoint);
translateAnimation.setRepeatMode(0);
translateAnimation.setDuration(500);
translateAnimation.setFillAfter(true);
excuseContainer.startAnimation(translateAnimation);

I'm trying to start animation from current y position of particular view (I do not need to change x position of view) But animation is staring every time from its first y point. How can I perform this action from current y position of view to desired position of view.

Here heightOfRootView stands for height of full screen, excuseContainer is that view which I want to move with animation and currentYPoint is last y point of excuseContainer.

EDIT: I there any Translate animation tutorial available. I searched for it but I din't found..

Thanks for your support.

like image 289
Sanjay Joshi Avatar asked Dec 27 '22 03:12

Sanjay Joshi


1 Answers

The 3rd parameter of the TranslateAnimation constructor you are using is a delta value, so the starting point is calculated like:

currentYPos + startingDeltaY

Since you seem to be passing in a Y value that refers to the location of something on the screen, this delta value won't be correct.

Try using this constructor:

public TranslateAnimation (int fromXType, float fromXValue, int toXType, float toXValue, int fromYType, float fromYValue, int toYType, float toYValue)

Like this:

new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0, Animation.ABSOLUTE, heightOfRootView-excuseContainer.getHeight(), Animation.ABSOLUTE, currentYPoint);
like image 196
Tushar Avatar answered Jan 06 '23 00:01

Tushar