How translation animation works: Android

I am trying to move a RelativeLayout using TranslateAnimation . The code I wrote to execute is this:

 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 the animation from the current y position of a certain view (I don’t need to change the position of the point of view) But the animation looks every time from the first point y. How can I perform this action from the current position y position to the desired view position.

Here, heightOfRootView denotes the height of the full screen, excuseContainer is the view I want to move with the animation, and currentYPoint is the last y point of excuseContainer .

EDIT: I have any animation translation tutorial. I searched for him, but I did not find ..

Thanks for your support.

+4
source share
1 answer

The third parameter of the TranslateAnimation constructor that you use is a delta value, so the starting point is calculated as:

currentYPos + startingDeltaY

Since you seem to be passing a Y value that refers to the location of something on the screen, this delta value will be incorrect.

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); 
+10
source

Source: https://habr.com/ru/post/1482500/


All Articles