この記事では、フレームアニメーションを実装するJavaの例について説明します。次のように、参照のために共有してください。
1。繁殖図
2。フレームアニメーションの簡単なコード
プライベートイメージビューbganimview; Private AnimationDrawable DanimationDrawable; // 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 duration = 50; ManimationDrawable.addframe(mcontext.getResources()。getDrawable(r.drawable.loading1)、duration); ManimationDrawable.addframe(mcontext.getResources()。getDrawable(r.drawable.loading2)、duration); ManimationDrawable.addframe(mcontext.getResources()。getDrawable(r.drawable.loading3)、duration); ManimationDrawable.setoneshot(false); Return ManimationDrawable; } // anime start public void animAnimloadingStart(){this.setVisability(view.visible); if(manimationdrawable!= null){manimationDrawable.start(); }} // anime end public void animainloadingend(){if(manimationdrawable!= null){manimationdrawable.stop(); } 3。拡張機能:
// X-Axis翻訳public void animy(int y、int nexty、int duration){linearinterpolator ll = new linearinterpolator(); //一定の速度ObjectAnimator Animator = objectAnimator.Offloat(YourView、 "Translation"、0、300); // 300それが負の値の場合、それは上向きのanimator.setduration(duration); Animator.setInterPolator(LL); Animator.start(); } // y-axis翻訳public void animx(int x、int nextx、int duration){linearinterpolator ll = new linearinterpolator(); ObjectAnimator Animator = ObjectAnimator.Offloat(YourView、 "TranslationX"、x、nextx); Animator.setDuration(持続時間); Animator.setInterPolator(LL); Animator.start(); } // Lonear Compression 0.5倍linearinterpolator ll = new linearinterpolator(); // static scaleanimation scaleanimation = new scaleanimation(1、1、1、0.5f); //(0,0)scaleanimation.setduration(500); scaleanimation.setinterpolator(ll); scaleanimation.setfillafter(true); chartview.startanimation(scaleanimation); //水平圧縮0.5回linearinterpolator ll = new linearInterpolator(); scaleanimation scaleanimation = new scaleanimation(1、0.5f、1、1); //デフォルト(0,0)scaleanimation.setduration(500); scaleanimation.setinterpolator(ll); scaleanimation.setfillafter(true); chartview.startanimation(scaleanimation);クリックして、素材のダウンロードアドレスを開きます
上記は、この記事のコンテンツ全体です。この記事の内容には、すべての人の研究や仕事に特定の参照値があることを願っています。ご質問がある場合は、メッセージを残してコミュニケーションをとることができます。 wulin.comへのご支援ありがとうございます。