如何使用旋转动画与翻译动画?

时间:2011-05-09 10:37:04

标签: android animation

我在我的示例应用程序中使用手势监听器,并且在其中; s onFling()方法我想要执行旋转和翻译动画。

个人都可以正常工作,但是当我将它集成到动画集中时,它无法正常工作。

请建议我如何处理。

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

onFling(MotionEvent e1,MotionEvent e2,float velocityX,             float velocityY){

    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);

}

感谢你很多

2 个答案:

答案 0 :(得分:0)

  

我想旋转图像并使用动画进行翻译。

使用AnimationSet

  

我也尝试使用AnimationSet,但同样没有任何事情发生。

然后您的代码中存在错误。

  

请建议我怎么做。

使用AnimationSet

答案 1 :(得分:0)

  

试试这个

 @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);

}
相关问题