This commit is contained in:
Horis 2024-01-23 17:30:11 +08:00
parent 7d552cc3eb
commit 9b49200a85

View File

@ -1,22 +1,21 @@
package io.legado.app.ui.widget.text
import android.content.Context
import android.graphics.Canvas
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatTextView
class MultilineTextView(context: Context, attrs: AttributeSet?) :
AppCompatTextView(context, attrs) {
override fun onDraw(canvas: Canvas) {
calculateLines()
super.onDraw(canvas)
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
val heightSize = MeasureSpec.getSize(heightMeasureSpec)
calculateLines(heightSize)
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
}
private fun calculateLines() {
val mHeight = measuredHeight
private fun calculateLines(measuredHeight: Int) {
val lHeight = lineHeight
val lines = mHeight / lHeight
val lines = measuredHeight / lHeight
setLines(lines)
}
}