如何将旋转动画与平移动画结合使用?

发布于 2024-11-06 13:44:00 字数 900 浏览 0 评论 0原文

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

individual 都工作正常,但是当我将其集成到 Animation Set 中时,它无法正常工作。

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

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

onFling(MotionEvent e1, MotionEvent e2, floatvelocityX, 浮动速度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);

}

非常感谢

I am using gesture listener in my sample app, and in it;s onFling() method I want to perform both Rotate and Translate Animation.

individual both work fine, but when I Integrate it in Animation Set , it's not work in proper .

Please suggest me how can I Handle this.

Following is code of my onFling method :

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

}

Thanking you lot

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幽梦紫曦~ 2024-11-13 13:44:00

试试这个

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

}

Try this

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

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文