Android -> how to animate to the new position

后端 未结 3 1110
粉色の甜心
粉色の甜心 2021-02-02 15:58

Here is simple xml android animation:



        
3条回答
  •  温柔的废话
    2021-02-02 16:24

    My solution:

    Thank you guys for your help. But I have fix my problem by other way, dynamically, without xml. Here's full code of this method:

    public void replace(int xTo, int yTo, float xScale, float yScale) {
            // create set of animations
            replaceAnimation = new AnimationSet(false);
            // animations should be applied on the finish line
            replaceAnimation.setFillAfter(true);
    
            // create scale animation
            ScaleAnimation scale = new ScaleAnimation(1.0f, xScale, 1.0f, yScale);
            scale.setDuration(1000);
    
            // create translation animation
            TranslateAnimation trans = new TranslateAnimation(0, 0,
                    TranslateAnimation.ABSOLUTE, xTo - getLeft(), 0, 0,
                    TranslateAnimation.ABSOLUTE, yTo - getTop());
            trans.setDuration(1000);
    
            // add new animations to the set
            replaceAnimation.addAnimation(scale);
            replaceAnimation.addAnimation(trans);
    
            // start our animation
            startAnimation(replaceAnimation);
        }
    

提交回复
热议问题