martes, 3 de febrero de 2015

Android: Simple animation

Animation
private void animateOpen() {

        Animation loadAnimation = AnimationUtils.loadAnimation(getContext(),
                R.anim.slide_in_from_top);
        loadAnimation.setFillAfter(true);
        loadAnimation.setAnimationListener(new AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {
                setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                opened = !opened;
            }
        });

        startAnimation(loadAnimation);
    }
res/anim/slide_in_from_top
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">

    <translate
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="500"
        android:fromYDelta="-100%"
        android:interpolator="@android:anim/decelerate_interpolator"
        android:toYDelta="0"
        android:zAdjustment="top" />

</set>

No hay comentarios:

Publicar un comentario