From c8a47f789150f683d4219db6eb00274dccae195d Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 22:38:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/widget/image/CoverImageView.kt | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt index eb82ad0d5..06cefd274 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt @@ -2,9 +2,7 @@ package io.legado.app.ui.widget.image import android.annotation.SuppressLint import android.content.Context -import android.graphics.Canvas -import android.graphics.Path -import android.graphics.Typeface +import android.graphics.* import android.graphics.drawable.Drawable import android.text.TextPaint import android.util.AttributeSet @@ -33,6 +31,11 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { defStyleAttr ) + init { + textPaint.typeface = Typeface.DEFAULT_BOLD + textPaint.isAntiAlias = true + } + override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { val measuredWidth = MeasureSpec.getSize(widthMeasureSpec) val measuredHeight = measuredWidth * 7 / 5 @@ -46,8 +49,8 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { super.onLayout(changed, left, top, right, bottom) width = getWidth().toFloat() height = getHeight().toFloat() - textPaint.textSize = width / 9 - textPaint.typeface = Typeface.DEFAULT_BOLD + textPaint.textSize = width / 8 + textPaint.strokeWidth = textPaint.textSize / 10 } override fun onDraw(canvas: Canvas) { @@ -69,7 +72,12 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { } super.onDraw(canvas) name?.let { - canvas.drawText(it, width / 3, height * 2 / 3, textPaint) + textPaint.color = Color.WHITE + textPaint.style = Paint.Style.STROKE + canvas.drawText(it, width / 6, height * 2 / 3, textPaint) + textPaint.color = Color.BLACK + textPaint.style = Paint.Style.FILL + canvas.drawText(it, width / 6, height * 2 / 3, textPaint) } }