You can use the abstract class Animation
to carry out the animation, and the class AlphaAnimation
to smooth the transition. Then just use the method setRepeatMode()
as REVERSE
and the method setRepeatCount()
passing by INFINITE
to repeat this animation until you leave the screen. See:
Programmatically:
Animation animation = new AlphaAnimation(1.0f, 0.0f);
// definição do tempo de duração da animação
animation.setDuration(500);
animation.setRepeatMode(Animation.REVERSE);
animation.setRepeatCount(Animation.INFINITE);
// aqui você coloca seu TextView ou ImageView, ou
// até mesmo outra view, da forma como você quiser
findViewById(R.id.textView).startAnimation(animation);
Using XML:
Or, you can create an XML inside the directory anim
res/anim/fadeinout.xml
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="500"
android:repeatCount="infinite"
android:repeatMode="reverse"
/>
In his main, you use the method AnimationUtils.loadAnimation()
in this way:
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.fadeinout);
findViewById(R.id.textView).startAnimation(animation);
As I described above, it will give effect to TextView
. If you choose a ImageView
, using the same code, the result will be this below:
...about 7 seconds
As you commented: "It’s gonna run for, like, seven seconds", just use the Handler()
. Behold:
// a animação deve estar fora do Handler.
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// aqui dentro você insere o código para sair dessa tela
}
}, 7000); // 7000 milesegundos equivale a 7 segundos.
Just to complement I want the text to be flashing very smooth,I think now I can explain
– luiz
Supplement by editing your question.. Remember that we will help you answer questions and not do the job for you. What you have tried to do?
– Bsalvo
Put a sample of your code we can help you better
– GabrielLocalhost
Have you looked here? https://developer.android.com/training/animation/index.html
– Márcio Oliveira
It would be nice if you put in the code you have now, so it doesn’t look like "do such a thing for me".
– LMaker