...
This commit is contained in:
parent
c249e79e9a
commit
55a0b209ec
@ -8,6 +8,10 @@ import android.text.Layout
|
||||
import android.text.StaticLayout
|
||||
import android.util.AttributeSet
|
||||
import androidx.appcompat.widget.AppCompatTextView
|
||||
import androidx.core.view.marginBottom
|
||||
import androidx.core.view.marginLeft
|
||||
import androidx.core.view.marginRight
|
||||
import androidx.core.view.marginTop
|
||||
import com.mime.dualscreenview.common.Blog
|
||||
import kotlinx.coroutines.MainScope
|
||||
import kotlinx.coroutines.launch
|
||||
@ -149,7 +153,7 @@ class PagedTextView : AppCompatTextView {
|
||||
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
||||
super.onSizeChanged(w, h, oldw, oldh)
|
||||
Blog.LOGD(log = "onSizeChanged>> ${this::class.java.name}")
|
||||
pageHeight = h
|
||||
pageHeight = ((h - (marginTop + marginBottom + paddingTop + paddingBottom)) * 0.85f).toInt()
|
||||
}
|
||||
|
||||
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
|
||||
@ -175,9 +179,9 @@ class PagedTextView : AppCompatTextView {
|
||||
pageList.clear()
|
||||
Blog.LOGD(log = "paginate>> ${this::class.java.name} && ${layout.text}")
|
||||
val layout = from(layout)
|
||||
val lines = if(min(maxLines, layout.lineCount) > 10) {min(maxLines, layout.lineCount) - 2} else {min(maxLines, layout.lineCount)}
|
||||
val lines = if(min(maxLines, layout.lineCount) > 10) {min(maxLines, layout.lineCount) - 1} else {min(maxLines, layout.lineCount)}
|
||||
var startOffset = 0
|
||||
val heightWithoutPaddings = (pageHeight - (paddingTop + paddingBottom)) * 0.85
|
||||
val heightWithoutPaddings = pageHeight - (marginTop + marginBottom + paddingTop + paddingBottom)
|
||||
var height = heightWithoutPaddings
|
||||
|
||||
for (i in 0 until lines) {
|
||||
@ -191,8 +195,13 @@ class PagedTextView : AppCompatTextView {
|
||||
|
||||
if (i == lines - 1) {
|
||||
pageList.add(
|
||||
if(layout.lineCount > i) {
|
||||
layout.text.subSequence(startOffset, layout.getLineEnd(i + 1))
|
||||
} else {
|
||||
layout.text.subSequence(startOffset, layout.getLineEnd(i))
|
||||
}
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
mPagedTextGenerateInterface?.completePagination(pageList)
|
||||
@ -214,7 +223,7 @@ class PagedTextView : AppCompatTextView {
|
||||
))
|
||||
} else {
|
||||
StaticLayout.Builder
|
||||
.obtain(originalText, 0, originalText.length, paint, layout.width - (paddingLeft + paddingRight))
|
||||
.obtain(originalText, 0, originalText.length, paint, ((layout.width - (paddingLeft + paddingRight + marginLeft + marginRight) * 0.85f)).toInt())
|
||||
.setAlignment(layout.alignment)
|
||||
.setLineSpacing(lineSpacingExtra, lineSpacingMultiplier)
|
||||
.setIncludePad(includeFontPadding)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user