如何使用动画移动和淡出任何视图

时间:2013-01-02 17:08:12

标签: android animation move fadeout alpha

好的,所以我有一个View,其中使用以下代码对其进行动画处理:

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

使用此代码,视图从屏幕的左侧开始并移动到几乎结束的屏幕,但我也希望淡出视图并最终隐藏/销毁它。我试图搜索与此相关的任何内容,但找不到任何内容。

感谢任何帮助。

3 个答案:

答案 0 :(得分:7)

试试这个

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

答案 1 :(得分:3)

    Animation a = new AlphaAnimation(1.0f, 0.0f);
        a.setDuration(1000);
        a.setFillAfter(true);
        iv.startAnimation(a);

AnimationSet set = new AnimationSet(true);
        set.addAnimation(animation)
        set.addAnimation(a)
        set.setFillAfter(true);
        iv.startAnimation(set);

    set.setAnimationListener(new AnimationListener() {

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

                    }

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

                    }

                    public void onAnimationEnd(Animation animation) {
                        iv.setVisibility(View.INVISIBLE);

                    }
                });

答案 2 :(得分:2)

通过使用http://nineoldandroids.com/提供的文件,我解决了这个问题。