Android – Imagen parpadeante utilizando la animación Alpha fade
He estado luchando por unos días en esto, finalmente sólo decidí preguntar. Es tan simple que tengo que estar perdiendo algo muy básico.
Tengo una página de diseño XML con una imagen definida. Tengo dos páginas anim XML, una para cambiar alfa de 0 a 1 y la otra desde 1 a 0 para crear un efecto "parpadeante". Así que la alphaAnimation se define en XML, solo necesito llamarla.
- Siempre se desvanecen en el marcador de posición con Picasso
- ¿El cargador universal de la imagen se descolora adentro del negro?
- Android Volley - ¿Cómo animar la carga de imágenes?
- Android Studio se desvanece en la pantalla principal
- Android Alpha se desvanece en el tema de la animación
La imagen aparece, pero no hay efecto de bucle.
public class blinker extends Activity { //create name of animation Animation myFadeInAnimation; Animation myFadeOutAnimation; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.scanning_view); //grab the imageview and load the animations ImageView myImageView = (ImageView) findViewById(R.id.blinkingView01); Animation myFadeInAnimation = AnimationUtils.loadAnimation(null, R.anim.fade_in); Animation myFadeOutAnimation = AnimationUtils.loadAnimation(null, R.anim.fade_out); //fade it in, and fade it out. myImageView.startAnimation(myFadeInAnimation); myImageView.startAnimation(myFadeOutAnimation); } }
Dos diseños de animación XML en el recurso Anim:
<?xml version="1.0" encoding="UTF-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:interpolator="@android:anim/accelerate_interpolator" android:duration="50" android:repeatCount="infinite"/> </set>
Y el otro:
<?xml version="1.0" encoding="UTF-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:interpolator="@android:anim/accelerate_interpolator" android:duration="1000" android:repeatCount="infinite"/> </set>
- ¿Cómo desaparecer y entre dos imágenes?
- Añadir animación diferente para diferentes fotogramas en vídeo con ffmpeg android
- Fadein fadein de animación alfa Android con retrasos
- Android se desvanece y se desvanece con ImageView
- Cómo hacer un fadein de una imagen en una pantalla de Android Activity?
- Cómo agregar animación a una vista de texto en android
- Animación de TextView: se desvanece, espera, se desvanece
¿Por qué no usar android:repeatMode="reverse"
La mejor manera de interrumpir el desvanecimiento:
ImageView myImageView = (ImageView) findViewById(R.id.imageView2); Animation myFadeInAnimation = AnimationUtils.loadAnimation(Splash.this, R.anim.tween); myImageView.startAnimation(myFadeInAnimation);
En su res / anim / crear tween.xml tween 1s empezar opacidad 0 a 1 y invertir infinit …
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="1000" android:repeatMode="reverse" android:repeatCount="infinite" /> </set>
Puede utilizar la siguiente animación alfa para establecer los efectos parpadeantes en las vistas de android.
blinkanimation= new AlphaAnimation(1, 0); // Change alpha from fully visible to invisible blinkanimation.setDuration(300); // duration blinkanimation.setInterpolator(new LinearInterpolator()); // do not alter animation rate blinkanimation.setRepeatCount(3); // Repeat animation infinitely blinkanimation.setRepeatMode(Animation.REVERSE);
Después de esto agregue la animación a su vista como,
view.setAnimation(blinkanimation);
o
view.startAnimation(blinkanimation);