Added grow animation to LrcView

This commit is contained in:
Prathamesh More 2022-01-04 14:26:22 +05:30
parent 956cce6989
commit 5a5b464057
4 changed files with 23 additions and 12 deletions

View file

@ -167,7 +167,7 @@ class CoverLrcView @JvmOverloads constructor(
isShowTimeline = false
removeCallbacks(hideTimelineRunnable)
mCurrentLine = centerLine
invalidate()
animateCurrentTextSize()
return true
}
} else {
@ -458,6 +458,7 @@ class CoverLrcView @JvmOverloads constructor(
mCurrentLine = line
if (!isShowTimeline) {
smoothScrollTo(line)
animateCurrentTextSize()
} else {
invalidate()
}
@ -536,6 +537,18 @@ class CoverLrcView @JvmOverloads constructor(
canvas.restore()
}
fun animateCurrentTextSize() {
val currentTextSize = mCurrentTextSize
ValueAnimator.ofFloat(mNormalTextSize, currentTextSize).apply {
addUpdateListener {
mCurrentTextSize = it.animatedValue as Float
invalidate()
}
duration = 300L
start()
}
}
@SuppressLint("ClickableViewAccessibility")
override fun onTouchEvent(event: MotionEvent): Boolean {
if (event.action == MotionEvent.ACTION_UP
@ -613,7 +626,7 @@ class CoverLrcView @JvmOverloads constructor(
private fun adjustCenter() {
smoothScrollTo(centerLine, ADJUST_DURATION)
}
/** 滚动到某一行 */
/** 滚动到某一行 */
private fun smoothScrollTo(line: Int, duration: Long = mAnimationDuration) {
val offset = getOffset(line)