mirror of
https://github.com/gedoor/legado.git
synced 2024-08-30 09:23:26 +08:00
优化
This commit is contained in:
parent
7d552cc3eb
commit
9b49200a85
@ -1,22 +1,21 @@
|
|||||||
package io.legado.app.ui.widget.text
|
package io.legado.app.ui.widget.text
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Canvas
|
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import androidx.appcompat.widget.AppCompatTextView
|
import androidx.appcompat.widget.AppCompatTextView
|
||||||
|
|
||||||
class MultilineTextView(context: Context, attrs: AttributeSet?) :
|
class MultilineTextView(context: Context, attrs: AttributeSet?) :
|
||||||
AppCompatTextView(context, attrs) {
|
AppCompatTextView(context, attrs) {
|
||||||
|
|
||||||
override fun onDraw(canvas: Canvas) {
|
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||||
calculateLines()
|
val heightSize = MeasureSpec.getSize(heightMeasureSpec)
|
||||||
super.onDraw(canvas)
|
calculateLines(heightSize)
|
||||||
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun calculateLines() {
|
private fun calculateLines(measuredHeight: Int) {
|
||||||
val mHeight = measuredHeight
|
|
||||||
val lHeight = lineHeight
|
val lHeight = lineHeight
|
||||||
val lines = mHeight / lHeight
|
val lines = measuredHeight / lHeight
|
||||||
setLines(lines)
|
setLines(lines)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user