Finally, a way to work has appeared, the right way to do this is: setFillAfter(true) ,
if you want to define your animation in xml you should do something like this
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/decelerate_interpolator" android:fillAfter="true"> <translate android:fromXDelta="0%" android:toXDelta="-100%" android:duration="1000"/> </set>
you can see that I defined filterAfter="true" in the set tag, if you try to define it in the translate tag, it will not work, there may be an error within!
and then in code
Animation anim = AnimationUtils.loadAnimation(this, R.anim.slide_out); someView.startAnimation(anim);
OR
TranslateAnimation animation = new TranslateAnimation(-90, 150, 0, 0); animation.setFillAfter(true); animation.setDuration(1800); someView.startAnimation(animation);
then it will certainly work!
Now this is a bit complicated, as the view does move to a new position, but in fact the pixels in the view move, i.e. your view is actually in the starting position, but it doesn’t appear, you can check it if you see some kind of button or clickable view in your view (in my case in the layout) to fix what you need to manually move your view / layout to a new position.
public TranslateAnimation (float fromXDelta, float toXDelta, float fromYDelta, float toYDelta) new TranslateAnimation(-90, 150, 0, 0);
now, as we see, our animation will start from -90 on the x axis to 150 on the x axis
what we do is set
someView.setAnimationListener(this);
and in
public void onAnimationEnd(Animation animation) { someView.layout(150, 0, someView.getWidth() + 150, someView.getHeight()); }
now let me explain public void layout (int left, int top, int right, int botton)
it moves your layout to a new position, the first argument defines the left one, we are 150 because the translation animation animated our view 150 x-axis , top is 0 because we did not animate the y axis, now we have done someView.getWidth() + 150 in the right someView.getWidth() + 150 , basically, we got the width of our view and added 150 , because on the left we now go to 150 x-axis to make the viewing width the original, and the bottom one is equal to the height of our view.
I hope you understand the concept of translation, and still you have questions that you can ask immediately in the comments section, I will be happy to help :)
EDIT Do not use the layout() method, as it can be called by the infrastructure, when the view is ever invalid and your changes will not be LayoutParams , use LayoutParams to set the layout parameters according to your requirement