Android ScaleAnimation and TranslateAnimation, how to avoid ScaleAnimation movement

前端 未结 4 1530
轮回少年
轮回少年 2021-02-09 19:11

I have an AnimationSet with inside a ScaleAnimation and a TranslateAnimation like this:

TranslateAnimation:

TranslateAnimation goTopFromRight =
        n         


        
相关标签:
4条回答
  • 2021-02-09 19:35

    To avoid the ScaleAnimation movement when using the ScaleAnimation and TranslateAnimation, you have to multiply the TranslateAnimation parametres with those from ScaleAnimation like this:

    TranslateAnimation goRightFromTop;
    ScaleAnimation sizeNotUp;
    
    goRightFromTop  = new TranslateAnimation(0,(-( invisibleCenterImageView.getLeft() - imageViewRight.getLeft() ))*(1/0.6667f), 0, (-( invisibleCenterImageView.getTop() - imageViewRight.getTop()))*(1/0.6667f)); 
    sizeNotUp       = new ScaleAnimation(1,0.6667f,1,0.6667f,Animation.RELATIVE_TO_SELF, (float)0.5, Animation.RELATIVE_TO_SELF, (float)0.5); 
    

    And then, surprise you deleted the ScaleAnimation movement.

    0 讨论(0)
  • 2021-02-09 19:38

    My solution is to add a container outside your view, and apply the scale animation to your view while applying translate animation to the container.
    Then you can make more complex animation even via XML~

    0 讨论(0)
  • 2021-02-09 19:42

    The correct solution is to change order of animations. Scale must go first:

    bringToTopFromRightAnimationSet.addAnimation(setSizeForTop);
    bringToTopFromRightAnimationSet.addAnimation(goTopFromRight);
    
    0 讨论(0)
  • 2021-02-09 19:44

    I remember having weird problems with nested animations as well. Have you tried setting the pivot point manually? See public ScaleAnimation (float fromX, float toX, float fromY, float toY, float pivotX, float pivotY) from http://developer.android.com/reference/android/view/animation/ScaleAnimation.html for it. It could work.

    0 讨论(0)
提交回复
热议问题