user8147458
user8147458

Reputation:

Android Fade In/Out animation from bottom to top

I am creating a animation in which I want to fade out my imageview but the fading animation should start from bottom to top unlike fading animation in which whole imageview fades at once.

public void animateFadeIn() {
    Animation in = AnimationUtils.loadAnimation(this,
            android.R.anim.fade_in);
    motherboard.startAnimation(in);
    motherboard.setVisibility(View.VISIBLE);
    in.setDuration(1500);
    in.setAnimationListener(new AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            // TODO Auto-generated method stub
            animateFadeOut();
        }
    });
}

How to achieve this.

<?xml version="1.0" encoding="UTF-8"?>

<scale
    android:fromYScale="-450"
    android:toYScale="450" />

<alpha
    android:duration="1500"
    android:fromAlpha="0.0"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:repeatCount="infinite"
    android:toAlpha="1.0" />

Upvotes: 3

Views: 4975

Answers (1)

AskNilesh
AskNilesh

Reputation: 69671

create a slide_up.xml in your

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
    android:duration="5000"
    android:fillAfter="true"
    android:fromYDelta="75%p"
    android:repeatCount="0"
    android:toYDelta="0%p" />

your fade_in.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >

   <alpha
    android:duration="1000"
    android:fromAlpha="0.0"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:toAlpha="1.0" />

</set>

than load animation

ImageView imageview;
Animation animFadein, animslideup;

animFadein = AnimationUtils.loadAnimation(getApplicationContext(),
            R.anim.fade_in);
    animslideup = AnimationUtils.loadAnimation(getApplicationContext(),
            R.anim.slide_up);

 final AnimationSet s = new AnimationSet(true);
    s.setInterpolator(new AccelerateInterpolator());

    s.addAnimation(animslideup);
    s.addAnimation(animFadein);
    imageview.startAnimation(s);

Upvotes: 2

Related Questions