Reputation: 12123
View move animation from the left to the right works ok
int startXposition = 5; // px
int endXposition = 960; // px
ImageView imageView = new ImageView(mContext);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(50, 50);
imageView.setImageResource(imageSrc);
params.setMargins(startXposition, 5, 0 ,0);
imageView.setLayoutParams(params);
mMainRootContrainer.addView(imageView);
ObjectAnimator objectanimatorX = ObjectAnimator.ofFloat(imageView, "x", endXposition);
...
But how to animate from the right to the left? When start x position value bigger then end x position value?
int startXposition = 1800;
int endXposition = 960;
...
When I set it bigger animation doesn't appear at all;
Upvotes: 0
Views: 1617
Reputation: 12123
actually it works I just forgot about my listener which removes visibilty of my imageView if start x position bigger then end x position
objectanimatorX.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
Float value = (Float) animation.getAnimatedValue();
if (value >= endXposition) {
imageView.setVisibility(View.GONE);
}
}
});
Upvotes: 0
Reputation: 1842
To move view from right-to-left
slide_in_right.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="@android:integer/config_mediumAnimTime"
android:fromXDelta="100%p"
android:interpolator="@android:anim/decelerate_interpolator"
android:toXDelta="0" />
Upvotes: 1