简体   繁体   中英

Translate animation & view layout

i'd like to make a translateAnimation in my Android app with the code below :

        TranslateAnimation anim = new TranslateAnimation(0,0,-400,0);
        anim.setDuration(400);
        anim.setAnimationListener(new AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {                     
            }

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

            }

            @Override
            public void onAnimationEnd(Animation animation) {

                mlLinearLayout.clearAnimation();
                mlLinearLayout.requestLayout();
                mlLinearLayout.layout(mlLinearLayout.getLeft(), mlLinearLayout.getTop()+400, mlLinearLayout.getRight(), mlLinearLayout.getBottom());
            }
        });
        anim.setInterpolator(new AccelerateInterpolator());
        anim.setFillEnabled(true);
        anim.setFillAfter(true);
        anim.setFillBefore(false);
        mlLinearLayout.startAnimation(anim);
        active=false;

but when this animation was done, the LinearLayout back to his start place even if I rebuild my view with the new position. How can I change it please ?

I finally found solution :

            TranslateAnimation anim = new TranslateAnimation(0,0,0,400);
            anim.setDuration(400);
            anim.setAnimationListener(new AnimationListener() {

                @Override
                public void onAnimationStart(Animation animation) {                     
                }

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

                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    mlLinearLayout.layout(mlLinearLayout.getLeft(), mlLinearLayout.getTop()+400, mlLinearLayout.getRight(), mlLinearLayout.getBottom());
                }
            });
            anim.setFillEnabled(true);
            anim.setFillAfter(false);
            anim.setFillBefore(false);
            mlLinearLayout.startAnimation(anim);
            active=false;

As i rebuild my view after translation, fillafter isn't usefull, Now it's working perfect without lag and jump !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM