diff --git a/app/src/main/res/layout/activity_simple.xml b/app/src/main/res/layout/activity_simple.xml index c19b86c9..95248d6c 100644 --- a/app/src/main/res/layout/activity_simple.xml +++ b/app/src/main/res/layout/activity_simple.xml @@ -6,11 +6,13 @@ android:layout_height="match_parent" android:background="#000000"> + \ No newline at end of file diff --git a/library/src/main/java/com/opensource/svgaplayer/SVGAImageView.kt b/library/src/main/java/com/opensource/svgaplayer/SVGAImageView.kt index 3c1759ab..b2c7e1cc 100644 --- a/library/src/main/java/com/opensource/svgaplayer/SVGAImageView.kt +++ b/library/src/main/java/com/opensource/svgaplayer/SVGAImageView.kt @@ -34,6 +34,9 @@ open class SVGAImageView : ImageView { var fillMode: FillMode = FillMode.Forward + // =0 means default speed,>1 speed up,<1 Slow down + var durationScaleRatio: Float = 0f + var callback: SVGACallback? = null private var animator: ValueAnimator? = null @@ -73,6 +76,7 @@ open class SVGAImageView : ImageView { private fun loadAttrs(attrs: AttributeSet) { val typedArray = context.theme.obtainStyledAttributes(attrs, R.styleable.SVGAImageView, 0, 0) loops = typedArray.getInt(R.styleable.SVGAImageView_loopCount, 0) + durationScaleRatio = typedArray.getFloat(R.styleable.SVGAImageView_durationScaleRatio, 0f) //new attr to adjust speed of animation clearsAfterStop = typedArray.getBoolean(R.styleable.SVGAImageView_clearsAfterStop, true) val antiAlias = typedArray.getBoolean(R.styleable.SVGAImageView_antiAlias, true) val autoPlay = typedArray.getBoolean(R.styleable.SVGAImageView_autoPlay, true) @@ -143,6 +147,12 @@ open class SVGAImageView : ImageView { } catch (e: Exception) {} animator.interpolator = LinearInterpolator() animator.duration = ((endFrame - startFrame + 1) * (1000 / it.FPS) / durationScale).toLong() + + //Adjust the duration,and no need to modify the .svga file. + if (durationScaleRatio > 0) { + animator.duration = (animator.duration / durationScaleRatio).toLong() + } + animator.repeatCount = if (loops <= 0) 99999 else loops - 1 animator.addUpdateListener { drawable.currentFrame = animator.animatedValue as Int diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index 218d96e6..ce69b6e4 100644 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -6,6 +6,7 @@ +