Move imageview after animation (update position)

后端 未结 4 1076
猫巷女王i
猫巷女王i 2020-12-17 06:49

I am trying to to do a translate animation on an image view from the bottom to the middle of the screen. Upon finish of the animation, I want the image view to stay there.

4条回答
  •  醉酒成梦
    2020-12-17 07:13

    Then you must set new LayoutParams for your View which is animating. When animation finishes, in your onAnimationEnd part, set new position of your View.

         TranslateAnimation translate = new TranslateAnimation(0, mDestLoc1[0]-mSrcLoc1[0], 0, mDestLoc1[1]-mSrcLoc1[1]);                   
         translate.setDuration(2000);
         translate.setAnimationListener(new AnimationListener(){
    
             @Override
             public void onAnimationStart(Animation animation) {}
    
             @Override
             public void onAnimationEnd(Animation animation) {
                 RelativeLayout.LayoutParams par = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
                 par.topMargin = mDestLoc1[1]-mSrcLoc1[1];
                 par.leftMargin = mDestLoc1[0]-mSrcLoc1[0];
                 view.setLayoutParams(par);              
             }
    
             @Override
             public void onAnimationRepeat(Animation animation) {}
    
         });
    
         view.startAnimation(translate);
    

提交回复
热议问题