There is an element (button), it occupies the screen floor and is nailed to the left edge of the screen. And there is such an animation

<translate android:fromXDelta="0" android:toXDelta="100%" android:duration="250" /> 

with it, I shift the button to the right for a given distance. How can you set a parameter to it so that the right edge of the button moves exactly to the right edge of the screen?

Add. Question: How to make the animation of the button smooth. In the sense that with a smooth shift to the right - there was no sharp jerk back!

  • On the vskidku - at least three ways you can do this, you need to use this particular animation or can you somehow in your own way? - Shwarz Andrei
  • Now I have no great experience with animation, so I looked at your options with pleasure. Just in case, I will add that the object I'm trying to animate is RelativeLayout. - Kirill Stoianov

1 answer 1

In the sense that with a smooth shift to the right - there was no sharp jerk back!

You need to use ObjectAnimator for this. Example:

 ObjectAnimator.ofFloat(yourButton, "x", yourButton.getX(), button.getX()+200) .setDuration(500) .start(); 

In this variant, we take the current position and shift the button by 200. There it remains:

enter image description here

To nail to the edge, take the current position, the width of the screen, the size of the button and move it to the required distance.