How to use View Animation

Asked

Viewed 132 times

2

I’d like to know how you would use View Animation ,to simulate a GIF.

For example: I have a picture of a sword, this sword is up, so do something like it goes right, clockwise,going around and going back to its original position.

Someone has worked this way before?

1 answer

1


Android provides various types of animations that can apply to a Imageview. The one that applies in your case is Rotateanimation.

Its use is done in 3 steps:

1 - Create an object of type Rotateanimation

//Cria uma animação de rotação desde de 0º a 360º com o eixo de rotação no centro da imagem.
RotateAnimation animation = new RotateAnimation(0f, 360f,
                                                Animation.RELATIVE_TO_SELF, 0.5f, 
                                                Animation.RELATIVE_TO_SELF, 0.5f);

2 - Define animation properties.

// 3 segundos.
long tempo = 3000;

//Define que a animação se processa de forma linear
animation.setInterpolator(new LinearInterpolator());

//Define o tempo da animação 
animation.setDuration(tempo);

3 - Start it.

imageView.startAnimation(animation);
  • I did it , but using an XML file , and there I configured it that you typed , but in the java class I used an Animation Object, I used the Load method, and I linked with the XML I created

Browser other questions tagged

You are not signed in. Login or sign up in order to post.