Reputation: 1
The users are allowed to change the Button position on the screen along the Y-axis using the slider. As this happens, I want to animate my Button. For example, the View is located at (0,0), and the user suddenly sets its position on (0, 420).
The Button should first fade out (from alpha 1.0 to alpha 0.0 in 400ms) while located at the current position(0,0).
Then, the Button location should change to (0,420), and it should fade in (from alpha 0.0 to alpha 1.0 in 400ms) while located at the changed position (0, 420).
As the Button location can be changed very quickly, what I got is a flashy animation effect, which I don't want. Here is my code:
/* Alpha from 1 to 0 */
ObjectAnimator animation = ObjectAnimator.ofFloat(myButton, "alpha", 1, 0);
animation.setDuration(400);
animation.setRepeatCount(1);
animation.setInterpolator(new LinearInterpolator());
animation.start();
/* Alpha from 0 back to 1 */
animation = ObjectAnimator.ofFloat(myButton, "alpha", 0, 1);
animation.setDuration(400);
animation.setRepeatCount(1);
animation.setInterpolator(new LinearInterpolator());
animation.start();
Upvotes: 0
Views: 146
Reputation: 1
I have found the solution using ValueAnimator:
ValueAnimator animator = ValueAnimator.ofInt((int) oldY, newY);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
params.y = (Integer) animation.getAnimatedValue();
mWindowManager.updateViewLayout(myView, params);
}
});
animator.start();
Upvotes: 0