1
votes

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

1

1 Answers

0
votes

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

}