From 8b45f9bcec03e048316fa6a9c32692fcdf276dff Mon Sep 17 00:00:00 2001 From: Hansin <845612500@qq.com> Date: Wed, 20 Feb 2019 16:50:11 +0800 Subject: [PATCH] Fix the bounds of SVGADrawable Override method onDraw() to set the bounds of SVGADrawable, then we can get the correct bounds. --- .../com/opensource/svgaplayer/SVGAImageView.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/library/src/main/java/com/opensource/svgaplayer/SVGAImageView.kt b/library/src/main/java/com/opensource/svgaplayer/SVGAImageView.kt index 81efaffc..cda31fbd 100644 --- a/library/src/main/java/com/opensource/svgaplayer/SVGAImageView.kt +++ b/library/src/main/java/com/opensource/svgaplayer/SVGAImageView.kt @@ -234,4 +234,20 @@ open class SVGAImageView : ImageView { stepToFrame(frame, andPlay) } + + override fun onDraw(canvas: Canvas?) { + super.onDraw(canvas) + + /** + * Fix the bounds of SVGADrawable + */ + if (drawable != null && drawable is SVGADrawable) { + var svgaDrawable = drawable as SVGADrawable + var w = svgaDrawable.videoItem.videoSize.width + var h = svgaDrawable.videoItem.videoSize.height + var scaleInfo = SVGAScaleInfo() + scaleInfo.performScaleType(canvas!!.width.toFloat(), canvas!!.height.toFloat(), svgaDrawable.videoItem.videoSize.width.toFloat(), svgaDrawable.videoItem.videoSize.height.toFloat(), scaleType) + svgaDrawable.setBounds(scaleInfo.tranFx.toInt(), scaleInfo.tranFy.toInt(), (scaleInfo.tranFx + w * scaleInfo.scaleFx).toInt(), (scaleInfo.tranFy + h * scaleInfo.scaleFy).toInt()) + } + } }