How a Translate Animation works: Android
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);
Sanjay Joshi
A passionate web UI developer, who loves to make things beautiful and interactive than ever. • is 9.5+ years of extensive experience. • Expertise in gamified, responsive and cross-platform web UI development. • 1.2 years of experience in iOS apps development. • 2 years of experience in Android apps development. • Intermediate experience in leading teams/projects. • Experience in conducting technical interviews.
Updated on July 05, 2022Comments
-
Sanjay Joshi almost 2 years
I'm trying to move a
RelativeLayout
usingTranslateAnimation
. 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 andcurrentYPoint
is last y point ofexcuseContainer
.EDIT: I there any Translate animation tutorial available. I searched for it but I din't found..
Thanks for your support.
-
Karan Khurana over 8 yearscan we start the animation of a window from a specific point and open on the screen? ex : a window opening from the point below a button, and covering the window below that button.