diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt index 7d4b9aba8..6fb4ce101 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt @@ -393,6 +393,18 @@ object ChapterProvider { } durY = 0f } + + // 图片居中:调整 X 坐标 + if (width < visibleWidth) { + val adjustWidth = (visibleWidth - width) / 2f + absStartX += adjustWidth.toInt() // 将起始 X 坐标移至居中位置 + } + + // 图片竖直方向居中:调整 Y 坐标 + if (height < visibleHeight) { + val adjustHeight = (visibleHeight - height) / 2f + durY = adjustHeight // 将 Y 坐标设置为居中位置 + } } else -> { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/TextChapterLayout.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/TextChapterLayout.kt index 0bd547ada..727fbcbf8 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/TextChapterLayout.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/TextChapterLayout.kt @@ -361,6 +361,18 @@ class TextChapterLayout( pendingTextPage = TextPage() durY = 0f } + + // 图片居中:调整 X 坐标 + if (width < visibleWidth) { + val adjustWidth = (visibleWidth - width) / 2f + absStartX += adjustWidth.toInt() // 将起始 X 坐标移至居中位置 + } + + // 图片竖直方向居中:调整 Y 坐标 + if (height < visibleHeight) { + val adjustHeight = (visibleHeight - height) / 2f + durY = adjustHeight // 将 Y 坐标设置为居中位置 + } } else -> {