|
|
@@ -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)
|
|
|
}
|
|
|
}
|