AndroidViewAnimations icon indicating copy to clipboard operation
AndroidViewAnimations copied to clipboard

Slide from position to targetPosition without fading

Open stanbar opened this issue 10 years ago • 2 comments

Hi. Is it possible to make slide animation from position 0 to target position without fading ?

stanbar avatar Sep 20 '15 19:09 stanbar

It would be very helpful for me as well if this is possible.

dogauzun avatar Oct 16 '15 13:10 dogauzun

It's actually quite simple to accomplish this by using your own BaseViewAnimator

I will take SlideInDownAnimator from the library as an example:

public class SlideInDownAnimator extends BaseViewAnimator {
    @Override
    public void prepare(View target) {
        int distance = target.getTop() + target.getHeight();
        getAnimatorAgent().playTogether(
                ObjectAnimator.ofFloat(target,"alpha",0,1),
                ObjectAnimator.ofFloat(target,"translationY",-distance,0)
        );
    }
}

If you want no fade in the animation, just copy the class to your project and remove 1 line:

public class SlideInDownAnimatorNoFade extends BaseViewAnimator {
    @Override
    public void prepare(View target) {
        int distance = target.getTop() + target.getHeight();
        getAnimatorAgent().playTogether(
                // ObjectAnimator.ofFloat(target,"alpha",0,1),
                ObjectAnimator.ofFloat(target,"translationY",-distance,0)
        );
    }
}

Then use it to perform your animation

YoYo.with(new SlideInDownAnimatorNoFade())
        .duration(700)
        .playOn(findViewById(R.id.edit_area));

robertoestivill avatar Oct 16 '15 13:10 robertoestivill