daimajia / AndroidViewAnimations

Cute view animation collection.
MIT License
12.42k stars 2.42k forks source link

Slide from position to targetPosition without fading #64

Open stanbar opened 9 years ago

stanbar commented 9 years ago

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

dogauzun commented 8 years ago

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

robertoestivill commented 8 years ago

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));