|
@@ -83,13 +83,13 @@ class SongLyricTextView @JvmOverloads constructor(
|
|
|
if (lineWidth <= consumeWidth) {
|
|
|
// 如果是之前已经变色区域,直接添加到path中
|
|
|
consumeWidth -= lineWidth
|
|
|
- path.addRect(
|
|
|
- layout.getLineLeft(i),
|
|
|
- layout.getLineTop(i).toFloat(),
|
|
|
- layout.getLineRight(i),
|
|
|
- layout.getLineBottom(i).toFloat(),
|
|
|
- Path.Direction.CCW
|
|
|
- )
|
|
|
+// path.addRect(
|
|
|
+// layout.getLineLeft(i),
|
|
|
+// layout.getLineTop(i).toFloat(),
|
|
|
+// layout.getLineRight(i),
|
|
|
+// layout.getLineBottom(i).toFloat(),
|
|
|
+// Path.Direction.CCW
|
|
|
+// )
|
|
|
} else {
|
|
|
// 如果该行正好是要变色的行,直接改变颜色
|
|
|
// 把需要的consumeWidth放入path中
|
|
@@ -120,7 +120,6 @@ class SongLyricTextView @JvmOverloads constructor(
|
|
|
|
|
|
if (lineWidth <= consumeWidth) {
|
|
|
// 如果是之前已经变色区域,直接添加到path中
|
|
|
- consumeWidth -= lineWidth
|
|
|
path.addRect(
|
|
|
layout.getLineLeft(i),
|
|
|
layout.getLineTop(i).toFloat(),
|
|
@@ -128,6 +127,10 @@ class SongLyricTextView @JvmOverloads constructor(
|
|
|
layout.getLineBottom(i).toFloat(),
|
|
|
Path.Direction.CCW
|
|
|
)
|
|
|
+
|
|
|
+ oldStartWidth -= lineWidth
|
|
|
+ consumeWidth -= lineWidth
|
|
|
+
|
|
|
} else {
|
|
|
// 如果该行正好是要变色的行,直接改变颜色
|
|
|
// 把需要的consumeWidth放入path中
|
|
@@ -149,6 +152,10 @@ class SongLyricTextView @JvmOverloads constructor(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private var startWidth : Float = 0f
|
|
|
+ private var endWidth : Float = 0f
|
|
|
+ private var oldStartWidth : Float = 0f
|
|
|
+
|
|
|
/**
|
|
|
* 开始播放
|
|
|
*
|
|
@@ -156,12 +163,13 @@ class SongLyricTextView @JvmOverloads constructor(
|
|
|
* @param endIndex 结束的文字的索引
|
|
|
* @param duration 播放时长
|
|
|
* */
|
|
|
- fun startPlayLine(startIndex: Int, endIndex: Int, duration: Long) {
|
|
|
+ fun startPlayLine(startIndex: Int, endIndex: Int,oldStart: Int, duration: Long) {
|
|
|
isPlaying = true
|
|
|
if (startIndex == -1) return
|
|
|
- val startWidth = mPaint.measureText(this.text.substring(0, startIndex))
|
|
|
- val endWidth = startWidth + mPaint.measureText(this.text.substring(startIndex, endIndex))
|
|
|
- animator.setFloatValues(startWidth, endWidth)
|
|
|
+ startWidth = mPaint.measureText(this.text.substring(0, startIndex))
|
|
|
+ oldStartWidth = mPaint.measureText(this.text.substring(0, oldStart))
|
|
|
+ endWidth = startWidth!! + mPaint.measureText(this.text.substring(startIndex, endIndex))
|
|
|
+ animator.setFloatValues(startWidth!!, endWidth!!)
|
|
|
animator.duration = if (duration > 0) duration else 10
|
|
|
animator.start()
|
|
|
}
|