In diesem Artikel wird der Beispielcode für Java beschrieben, um Frame -Animation zu implementieren. Teilen Sie es für Ihre Referenz wie folgt weiter:
1. Fortpflanzungsdiagramm
2. Kurzer Code für Frame Animation
private ImageView Bganimview; private AnimationDrawable ManimationDrawable; // ManimationDrawable = new AnimationDrawable () initialisieren; bganimview = new ImageView (Mcontext); bganimview.setbackgroundDrawable (getanimationDrawable (ManimationDrawable)); params = new Framelayout.layoutParams (viewGroup.layoutParams.wrap_content, viewGroup.layoutParams.wrap_content); params.topmargin = util.div (176 + 58); params.gravity = gravity.center_horizontal; AddView (BganImview, Params); private AnimationDrawable getanimationDrawable (AnimationDrawable ManimationDrawable) {int duration = 50; ManimationDrawable.Addframe (mcontext.getResources (). getDrawable (r.Drawable.loading1), Dauer); ManimationDrawable.AddFrame (mcontext.getResources (). getDrawable (R.Drawable.loading2), Dauer); ManimationDrawable.AddFrame (mcontext.getResources (). getDrawable (r.Drawable.loading3), Dauer); ManimationDrawable.Setoneshot (falsch); return ManimationDrawable; } // Anime starten public void AnimloadingStart () {this.setviability (view.visible); if (ManimationDrawable! = null) {ManimationDrawable.start (); }} // Anime End public void Animloadingend () {if (ManimationDrawable! = Null) {ManimationDrawable.Stop (); } 3. Erweiterung:
// x-achse Übersetzung public void Animy (int y, int nexty, int duration) {linearinterpolator ll = new LinearInterpolator (); // Konstantgeschwindigkeits-Objektanimator Animator = Objektanimator.offloat (YourView, "Translationy", 0, 300); // 300 Wenn es sich um einen negativen Wert handelt, wird es nach oben übersetzt. Animator.SetInterpolator (LL); Animator.Start (); } // y-axis Translation public void Animx (int x, int nextx, int duration) {linearinterpolator ll = neu linearinterpolator (); Objektanimator Animator = Objektanimator.offloat (YourView, "TranslationX", X, NextX); Animator.SetDuration (Dauer); Animator.SetInterpolator (LL); Animator.Start (); } // Loneare Komprimierung 0,5 -mal linearinterpolator ll = neuer linearinterpolator (); // statische Skaleanimation scaleanimation = new scaleanimation (1, 1, 1, 0,5f); // Standard aus (0,0) scaleanimation.setDuration (500); scaleanimation.setInterpolator (LL); scaleanimation.setFillAfter (true); ChartView.Startanimation (Skaleanimation); // Horizontale Komprimierung 0,5 -mal linearinterpolator ll = neu linearinterpolator (); Scaleanimation scaleanimation = neue skaleanimation (1, 0,5f, 1, 1); // standardnaug von (0,0) scaleanimation.setDuration (500); scaleanimation.setInterpolator (LL); scaleanimation.setFillAfter (true); ChartView.Startanimation (Skaleanimation);Klicken Sie hier, um die Download -Adresse des Materials zu öffnen
Das obige ist der gesamte Inhalt dieses Artikels. Ich hoffe, dass der Inhalt dieses Artikels einen gewissen Referenzwert für das Studium oder die Arbeit eines jeden hat. Wenn Sie Fragen haben, können Sie eine Nachricht zur Kommunikation überlassen. Vielen Dank für Ihre Unterstützung bei Wulin.com.