Este artículo describe el código de ejemplo para Java para implementar la animación de cuadro. Compártelo para su referencia, como sigue:
1. Diagrama de reproducción
2. Breve código para la animación de cuadro
ImageView privado Banimview; Animación privada ManimationDrawable de manimación; // Inicializar manimationDrawable = new AnimationDrawable (); bganimview = new ImageView (Mcontext); bganimview.setbackgroundDrawable (getAnimationDrawable (manimationDrawable)); Params = new Framelayout.LayoutParams (vergroup.layoutparams.wrap_content, vergroup.layoutparams.wrap_content); params.topmargin = util.div (176 + 58); params.gravity = gravity.center_horizontal; AddView (Bganimview, Params); Animación privada GetAnimationDrawable (AnimationDrawable ManimationDrawable) {int duración = 50; ManimationDrawable.AddFrame (Mcontext.getResources (). GetDrawable (R.Drawable.Loading1), Duración); ManimationDrawable.AddFrame (Mcontext.getResources (). GetDrawable (R.Drawable.Loading2), Duración); ManimationDrawable.AddFrame (Mcontext.getResources (). GetDrawable (R.Drawable.Loading3), Duración); manimationDrawable.setOneshot (falso); return manimationDrawable; } // anime start public void animloadingStart () {this.setVisability (ver.Visible); if (manimationDrawable! = null) {manimationDrawable.start (); }} // anime end public void animloadingEnd () {if (maniMationDrawable! = Null) {maniMationDrawable.stop (); } 3. Extensión:
// traducción del eje x public void animy (int y, int nexty, int duración) {linealInterpolator ll = new LinearInterpolator (); // Constant-Speed Objectanimator animator = Objectanimator.Offloat (YourView, "Tradationy", 0, 300); // 300 Si es un valor negativo, se traduce hacia arriba Animator.SetDuration (Duración); animator.setInterpolator (LL); animator.start (); } // traducción del eje y public void animx (int x, int nextx, int duration) {linealInterpolator ll = new LinearInterpolator (); ObjectAnimator animator = Objectanimator.Offloat (YourView, "TranslationX", X, NextX); animator.setDuration (duración); animator.setInterpolator (LL); animator.start (); } // compresión lonear 0.5 veces linealInterpolator ll = new LinearInterpolator (); // ScaleAnimation estático ScaleAnimation = New ScaleEnimation (1, 1, 1, 0.5f); // Deflamado de (0,0) ScaleAnimation.setDury (500); ScaleAnimation.SetInterpolator (LL); scaleanimation.setFillAfter (verdadero); ChartView.Startanimation (ScaleAnimation); // compresión horizontal 0.5 veces linealInterpolator ll = new LinearInterpolator (); ScaleAnimation ScaleAnimation = nueva escala de escala (1, 0.5f, 1, 1); // predeterminado de (0,0) ScaleAnimation.SetDuration (500); ScaleAnimation.SetInterpolator (LL); scaleanimation.setFillAfter (verdadero); ChartView.Startanimation (ScaleAnimation);Haga clic para abrir la dirección de descarga del material
Lo anterior es todo el contenido de este artículo. Espero que el contenido de este artículo tenga cierto valor de referencia para el estudio o el trabajo de todos. Si tiene alguna pregunta, puede dejar un mensaje para comunicarse. Gracias por su apoyo a Wulin.com.