How to move and fade out any View with Animation

Tolga Demir picture Tolga Demir · Jan 2, 2013 · Viewed 8.7k times · Source

Ok, so I have a View where its being animated with the following code:

RelativeLayout rl = (RelativeLayout) findViewById(R.id.productPage_parentLayout_RL);

ImageView iv = new ImageView( ProductPage.this );
imageLoader.DisplayImage(FULL_PRODUCT_INFO.getFirstImage(), iv);

Animation animation = new TranslateAnimation(0, helper.getDeviceWidth() - 100,0, 0);
animation.setDuration(1000);
animation.setFillAfter(true);

rl.addView(iv);

With this code, the view starts from the left side of the screen and moves to almost the end of the screen, but I also want to fade-out the view and hide/destroy it in the end. I tried to search anything related to this, but couldn't find any.

Any help is appreciated.

Answer

yogi picture yogi · Jan 2, 2013

Try this

ObjectAnimator move=ObjectAnimator.ofFloat(iv, "translationY",100f);
                    move.setDuration(3000);
    ObjectAnimator alpha1=ObjectAnimator.ofFloat(iv, "alpha",0.5f);
                    alpha1.setDuration(1000);

                    ObjectAnimator alpha2=ObjectAnimator.ofFloat(iv, "alpha",0);
                    alpha2.setDuration(2000);
    AnimatorSet animset=new AnimatorSet();
                    animset.play(alpha2).before(alpha1).with(move);
                    animset.start();