setAnimation vs startAnimation in android

前端 未结 2 821
名媛妹妹
名媛妹妹 2020-12-20 12:06

I basically want to move a view from 1 location to another, plus I also want to increase its height gradually, So what should I use setAnimation or startAnimation.



        
2条回答
  •  梦毁少年i
    2020-12-20 12:27

    Use startAnimation.

    Below is sample Snippet

    trans = new TranslateAnimation(0, 100, 0, 100);
    trans.setDuration(250);
    trans.setInterpolator(new AccelerateInterpolator(1.0f));
    someView.startAnimation(trans);
    

    plus i also want to increase its height gradually,

    For this you will Scale animation.

    If you want to combine them into single file use Set.

     
    
       
       
    
    

    Place the below code inside the java file:

    Animation logoMoveAnimation = AnimationUtils.loadAnimation(this, R.anim.logoanimation); 
    logoIV.startAnimation(logoMoveAnimation);
    

    setAnimation

    Sets the next animation to play for this view.But view animation does not start yet.

    startAnimation

    If you want the animation to play immediately, use startAnimation. This method provides allows fine-grained control over the start time and invalidation, but you must make sure that

    1) the animation has a start time set,

    2) the view will be invalidated when the animation is supposed to start.

提交回复
热议问题