Cet article décrit l'exemple de code pour Java pour implémenter l'animation de trame. Partagez-le pour votre référence, comme suit:
1. Diagramme de reproduction
2. Brief code pour l'animation de trame
ImageView privé BganimView; Private Animation Dreat ManimationDrawable; // initialiser ManimationDrawable = new AnimationDrawable (); 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 Durée = 50; ManimationDrawable.AddFrame (mContext.getResources (). GetDrawable (R.Drawable.Loading1), durée); ManimationDrawable.AddFrame (mContext.getResources (). GetDrawable (R.Drawable.Loading2), durée); ManimationDrawable.AddFrame (mContext.getResources (). GetDrawable (R.Drawable.Loading3), durée); ManimationDrawable.Setoneshot (false); retour manimmationradevable; } // anime start public void animaLingStart () {this.setVisibility (View.Visible); if (ManimationDrawable! = null) {ManimationDrawable.start (); }} // anime end public void animaLingingEnd () {if (ManimationDrawable! = Null) {ManimationDrawable.stop (); } 3. Extension:
// Traduction x-axe public void Animy (int y, int nexty, int durée) {lineArinterpolateur ll = new linearinterpoLator (); // Animateur objectAnmator de constante-vitesse = ObjectAnimator.offloat (YourView, "traduction", 0, 300); // 300 Si c'est une valeur négative, il est traduit vers le haut Animator.SetDuration (durée); animator.setinterpolator (ll); animator.start (); } // Traduction Y-axis public void animx (int x, int nextx, int durée) {lineaterpolator ll = new linearinterpolateur (); ObjectAnimator Animator = ObjectAnimator.Offloat (YourView, "traductionx", x, nextX); Animator.SetDuration (durée); animator.setinterpolator (ll); animator.start (); } // compression lonear 0,5 fois linearinterpolator ll = new linearinterpolator (); // static scaleanimation scaleanimation = new Scaleanimation (1, 1, 1, 0,5f); // par défaut de (0,0) Scaleanimation.SetDuration (500); Scaleanimation.setinterPolator (LL); Scaleanimation.setFillafter (true); ChartView.StartAnimation (Scaleanimation); // Compression horizontale 0,5 fois linearinterpolator ll = new linearinterpolator (); Scaleanimation Scaleanimation = new Scaleanimation (1, 0,5f, 1, 1); // par défaut de (0,0) Scaleanimation.setDuration (500); Scaleanimation.setinterPolator (LL); Scaleanimation.setFillafter (true); ChartView.StartAnimation (Scaleanimation);Cliquez pour ouvrir l'adresse de téléchargement du matériel
Ce qui précède est l'intégralité du contenu de cet article. J'espère que le contenu de cet article a une certaine valeur de référence pour l'étude ou le travail de chacun. Si vous avez des questions, vous pouvez laisser un message pour communiquer. Merci pour votre soutien à wulin.com.