Как использовать анимацию поворота с анимацией перевода? - PullRequest
1 голос
/ 09 мая 2011

Я использую слушатель жестов в моем примере приложения, и в нем; с помощью метода onFling () я хочу выполнять анимацию как вращения, так и перевода.

отдельные работают нормально, но когда я интегрирую их в набор анимации, это не будет работать должным образом.

Пожалуйста, предложите мне, как я могу справиться с этим.

Ниже приведен код моего метода 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);

}

Большое спасибо

Ответы [ 2 ]

0 голосов
/ 18 мая 2015

Попробуйте это

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

}
0 голосов
/ 09 мая 2011

Я хочу повернуть изображение вместе с переводом с помощью анимации.

Используйте AnimationSet.

Я тоже пробовал с AnimationSet, но ничего не происходит.

Тогда в вашем коде есть ошибка.

Пожалуйста, предложите мне, как я могу это сделать.

Используйте AnimationSet.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...