【问题标题】:How to use Rotate Animation with Translate animation?如何使用旋转动画和平移动画?
【发布时间】:2011-08-21 14:18:55
【问题描述】:

我在我的示例应用程序中使用手势监听器,我想在它的 onFling() 方法中执行旋转和平移动画。

个人都可以正常工作,但是当我将它集成到 Animation Set 时,它不能正常工作。

请建议我如何处理这个问题。

以下是我的 onFling 方法的代码:

onFling(MotionEvent e1, MotionEvent e2, 浮动速度X, 浮动速度Y) {

    translateAnimation =  new TranslateAnimation(0,x2,0,y2); // x2=e2.getX() and y2=e2.getY()

    translateAnimation.setDuration(3000);

    rotateAnimation = new RotateAnimation(0, 90, RotateAnimation.RELATIVE_TO_SELF, RotateAnimation.RELATIVE_TO_SELF);

    rotateAnimation.setStartOffset(1400);

    rotateAnimation.setInterpolator(new AccelerateInterpolator());


    animationSet.addAnimation(translateAnimation);

    animationSet.addAnimation(rotateAnimation);

    animationSet.setAnimationListener(this);

    animationSet.setDuration(3000);

    lastView.startAnimation(animationSet);

}

非常感谢

【问题讨论】:

    标签: android animation


    【解决方案1】:

    试试这个

     @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.rotate);
        AnimationSet snowMov1 = new AnimationSet(true);
        RotateAnimation rotate1 = new RotateAnimation(0, 360,
                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
                0.5f);
        rotate1.setStartOffset(50);
        rotate1.setDuration(300);
        rotate1.setRepeatCount(-1);
        snowMov1.addAnimation(rotate1);
        TranslateAnimation trans1 = new TranslateAnimation(
                Animation.RELATIVE_TO_PARENT, 0.1f,
                Animation.RELATIVE_TO_PARENT, 0.3f,
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, 0.9f);
        trans1.setDuration(300);
        trans1.setRepeatCount(-1);
    
        snowMov1.addAnimation(trans1);
        ImageView view = (ImageView) findViewById(R.id.image);
        view.startAnimation(snowMov1);
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-22
      • 2019-03-10
      • 2013-11-23
      • 2019-02-05
      • 2015-05-25
      • 2021-08-15
      • 2014-02-01
      • 2013-12-27
      相关资源
      最近更新 更多