Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Fix the bounds of SVGADrawable #119

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions library/src/main/java/com/opensource/svgaplayer/SVGAImageView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
}