【问题标题】:Can we use Android TranslateAnimation for 2 different location?我们可以将 Android TranslateAnimation 用于 2 个不同的位置吗?
【发布时间】:2015-09-29 14:17:11
【问题描述】:

TranslateAnimation 用于将图像移动到不同的位置 like

  1. 从左到右
  2. 从上到下
  3. 一个 XY 缩放位置到另一个 XY 缩放位置

语法

TranslateAnimation animation = new TranslateAnimation(StartinXscale,StartingYscale,EndXscale,EndYscale);

方法

animation.setDuration(millisecond);//move speed.
animation.setRepeatCount(int value);//how many time you want to move it from starting to ending position.
animation.setRepeatMode(int value);//mode like goto destination and return back to main position. 
imageView.startAnimation(animation);//Start animation on imageView

我们可以在一个活动中使用上述代码两次吗?


我的代码

private void animationAction() {
        float StartX = 500.0f;
        float StartY = -300.0f;
        float EndX = -300.0f;
        float EndY = 500.0f;
        int i = 0;
        for (i = 0; i <2; i++) {
                TranslateAnimation animation = new TranslateAnimation(StartX,StartX + EndX, StartY, StartY + EndY);
                animation.setDuration(3000);
                animation.setRepeatCount(5);
                animation.setRepeatMode(2);
                animation.setFillAfter(true);
                img_animation.startAnimation(animation);
                EndX = 300.0f;

        }

MyCode 结果只执行一次


【问题讨论】:

    标签: android translate-animation


    【解决方案1】:
    // Animation
        private Animation animMove;
        private Animation animFadein;
    
    //Method to preform 2 animation in sequence  
    
    private void doAnimation() {
            // load the animation
            animMove = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.move);
            animFadein = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade_in);
            // start move up animation on brnetwork text
            imageView.startAnimation(animMove);
            // set animation listener
            animMove.setAnimationListener(new AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {
                    // TODO Auto-generated method stub
                }
    
                @Override
                public void onAnimationRepeat(Animation animation) {
                    // TODO Auto-generated method stub
                }
    
                @Override
                public void onAnimationEnd(Animation animation) {
    
                    Resources res = getResources();
                    Drawable drawable = res.getDrawable(R.drawable.background);
                    relMain.setBackgroundDrawable(drawable);
    
                    llInput.startAnimation(animFadein);
                    llInput.setVisibility(View.VISIBLE);
                    tvSignUp.startAnimation(animFadein);
                    tvVideo.startAnimation(animFadein);
                    tvSignUp.setVisibility(View.VISIBLE);
                    tvVideo.setVisibility(View.VISIBLE);
                }
            });
    
            // set animation listener
            animFadein.setAnimationListener(new AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {
                    // TODO Auto-generated method stub
                }
    
                @Override
                public void onAnimationRepeat(Animation animation) {
                    // TODO Auto-generated method stub
                }
    
                @Override
                public void onAnimationEnd(Animation animation) {
                    // TODO Auto-generated method stub
                }
            });
    
        }
    
    after MOVE animation i have to perform FEDIN animation
    in your case you can replace FEDIN by your Next Animation.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-16
      • 2016-03-19
      • 2022-01-13
      • 1970-01-01
      • 2019-03-15
      • 1970-01-01
      • 1970-01-01
      • 2018-08-23
      相关资源
      最近更新 更多