From f4fe3206f76e2c20fa65138ab94a24f1505c5400 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 7 Mar 2020 17:16:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/widget/text/MultilineTextView.kt | 27 +++++++++++++++++++ app/src/main/res/layout/item_search.xml | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/io/legado/app/ui/widget/text/MultilineTextView.kt 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" /> -