Cómo hacer una transición suave de una imagen a otra
Tengo una actividad donde estoy cambiando el ImageView periódicamente, para eso escribí la línea de código abajo.
imageview.setImageUri(resId);
Estoy aumentando el id de recurso. Funciona bien, pero hay una transición repentina de una imagen a otra. No quiero eso, quiero la transición suave de la imagen de ver a otra imagen. ¿Cómo puedo hacer eso?
- Cómo aplicar sombra a ImageView?
- Cómo especificar imágenes diferentes cuando mi widget personalizado tiene el foco
- Obtenga la imagen del recurso por nombre en el adaptador de cursor personalizado
- FindViewById devuelve el elemento erróneo?
- Cómo desvanecer imagen en ImageView cargado de url
- Cómo configurar onClicklistener Método de ImageView en Android?
- ImageView amplía la animación corta la imagen
- Cómo tener una imagen de fondo de pantalla completa (con centro de cultivo) que no cambia el tamaño
- ImageView carga la imagen de alta resolución como muy mala calidad
- Cómo dibujar líneas sobre ImageView en Android?
- Utilice ImageView con GridView para establecer el número de imágenes que se muestran en las filas y columnas
- Cómo agregar efectos de imagen en android?
- Imagen de alta resolución - OutOfMemoryError
Prueba esto
ImageView demoImage = (ImageView) findViewById(R.id.DemoImage); int imagesToShow[] = { R.drawable.image1, R.drawable.image2,R.drawable.image3 }; animate(demoImage, imagesToShow, 0,false); private void animate(final ImageView imageView, final int images[], final int imageIndex, final boolean forever) { //imageView <-- The View which displays the images //images[] <-- Holds R references to the images to display //imageIndex <-- index of the first image to show in images[] //forever <-- If equals true then after the last image it starts all over again with the first image resulting in an infinite loop. You have been warned. int fadeInDuration = 500; // Configure time values here int timeBetween = 3000; int fadeOutDuration = 1000; imageView.setVisibility(View.INVISIBLE); //Visible or invisible by default - this will apply when the animation ends imageView.setImageResource(images[imageIndex]); Animation fadeIn = new AlphaAnimation(0, 1); fadeIn.setInterpolator(new DecelerateInterpolator()); // add this fadeIn.setDuration(fadeInDuration); Animation fadeOut = new AlphaAnimation(1, 0); fadeOut.setInterpolator(new AccelerateInterpolator()); // and this fadeOut.setStartOffset(fadeInDuration + timeBetween); fadeOut.setDuration(fadeOutDuration); AnimationSet animation = new AnimationSet(false); // change to false animation.addAnimation(fadeIn); animation.addAnimation(fadeOut); animation.setRepeatCount(1); imageView.setAnimation(animation); animation.setAnimationListener(new AnimationListener() { public void onAnimationEnd(Animation animation) { if (images.length - 1 > imageIndex) { animate(imageView, images, imageIndex + 1,forever); //Calls itself until it gets to the end of the array } else { if (forever == true){ animate(imageView, images, 0,forever); //Calls itself to start the animation all over again in a loop if forever = true } } } public void onAnimationRepeat(Animation animation) { // TODO Auto-generated method stub } public void onAnimationStart(Animation animation) { // TODO Auto-generated method stub } }); }
Pruebe la animación alfa. Primero desvanezca la vista de la imagen, en el extremo de la animación, cambie el recurso y luego desvanezca la vista de la imagen.
Para una transición suave, debes utilizar Animaciones en Android, comienza leyendo el siguiente enlace: http://www.vogella.com/articles/AndroidAnimation/article.html
Hay muchas preguntas similares sobre stackoverflow sobre animaciones y muchos tutoriales están disponibles en la red acerca de este tema. Una búsqueda simple en google le traerá toneladas de resultado
- GetChildView no se llama
- Seleccionar la API de destino en la vista previa de diseño de diseño de Android Studio