Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

215
Vistas
Cómo repetir la animación de Android

Estoy tratando de obtener dos vistas para moverme al centro de la pantalla y recuperarme x cantidad de veces.

Este código hace eso pero se ejecuta solo una vez. ` val view = findViewById(R.id.imageView2)

 val animation = SpringAnimation(view, DynamicAnimation.TRANSLATION_Y, 0f) val view2 = findViewById<View>(R.id.imageView3) val animation2 = SpringAnimation(view2, DynamicAnimation.TRANSLATION_Y, 0f) findViewById<View>(R.id.imageView2).also { img -> SpringAnimation(img, DynamicAnimation.TRANSLATION_Y).apply { animation.getSpring().setDampingRatio(SpringForce.DAMPING_RATIO_HIGH_BOUNCY) animation.spring.stiffness = SpringForce.STIFFNESS_VERY_LOW animation.animateToFinalPosition(50f) } } findViewById<View>(R.id.imageView3).also { img -> SpringAnimation(img, DynamicAnimation.TRANSLATION_Y).apply { animation2.getSpring().setDampingRatio(SpringForce.DAMPING_RATIO_HIGH_BOUNCY) animation2.spring.stiffness = SpringForce.STIFFNESS_VERY_LOW animation2.animateToFinalPosition(-100f) } }`

Entonces, ¿cómo hago para que se ejecute x número de veces? Esto es obviamente Spring Animation, pero no estoy casado con eso. Si hay otra animación que lograría esto, estaría totalmente abierto a cambiar.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Establecer android:repeatCount="infinite" en la carpeta anim

over 4 years ago · Santiago Trujillo Denunciar

0

Puede ejecutar varias SpringAnimation s en la misma View llamando repetidamente a animateToFinalPosition(translation) con una secuencia de valores de traducción .

Por ejemplo:

 startSpringAnimations(findViewById<View>(R.id.imageView1), 300f, 6) startSpringAnimations(findViewById<View>(R.id.imageView2), -600f, 6)

con una función

 /** * [view] will be moved using [times] SpringAnimations over a distance of abs([totalTranslation]) * If [totalTranslation] is negative, direction will be up, else down */ private fun startSpringAnimations(view: View, totalTranslation: Float, times: Int ) { if(times <= 0){ return } val translation = totalTranslation/ times.toFloat() SpringAnimation(view, DynamicAnimation.TRANSLATION_Y, 0f).apply{ spring.dampingRatio = SpringForce.DAMPING_RATIO_HIGH_BOUNCY spring.stiffness = SpringForce.STIFFNESS_VERY_LOW addEndListener(object: DynamicAnimation.OnAnimationEndListener{ private var count = 1 override fun onAnimationEnd(animation1: DynamicAnimation<*>?, canceled: Boolean, value: Float, velocity: Float) { Log.d("SpringAnimation", "onAnimationEnd: animation $animation1 canceled $canceled value $value velocity $velocity count $count") if (canceled) return count++ if(count <= times){ animateToFinalPosition(translation * count) } } }) animateToFinalPosition(translation) } }
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda