diff --git a/app/src/main/java/io/legado/app/ui/widget/text/MultilineTextView.kt b/app/src/main/java/io/legado/app/ui/widget/text/MultilineTextView.kt new file mode 100644 index 000000000..c0ccd86da --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/widget/text/MultilineTextView.kt @@ -0,0 +1,27 @@ +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) { + + private var calculatedLines = false + + override fun onDraw(canvas: Canvas?) { + if (!calculatedLines) { + calculateLines(); + calculatedLines = true; + } + super.onDraw(canvas) + } + + private fun calculateLines() { + val mHeight = measuredHeight + val lHeight = lineHeight + val lines = mHeight / lHeight + setLines(lines) + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/item_search.xml b/app/src/main/res/layout/item_search.xml index 65e518c60..2942b5db5 100644 --- a/app/src/main/res/layout/item_search.xml +++ b/app/src/main/res/layout/item_search.xml @@ -75,7 +75,7 @@ android:textColor="@color/tv_text_default" android:textSize="12sp" /> -