Skip to content
This repository was archived by the owner on Nov 10, 2025. It is now read-only.

Commit d110a4e

Browse files
committed
Merge branch 'view_size_change' of https://github.com/OstAlex/AndroidPdfViewer into OstAlex-view_size_change
2 parents af6d8a3 + a31e5d4 commit d110a4e

File tree

1 file changed

+23
-3
lines changed
  • android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer

1 file changed

+23
-3
lines changed

android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/PDFView.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,13 +474,33 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
474474
if (isInEditMode() || state != State.SHOWN) {
475475
return;
476476
}
477+
478+
// calculates the position of the point which in the center of view relative to big strip
479+
float centerPointInStripXOffset = -currentXOffset + oldw * 0.5f;
480+
float centerPointInStripYOffset = -currentYOffset + oldh * 0.5f;
481+
482+
float relativeCenterPointInStripXOffset;
483+
float relativeCenterPointInStripYOffset;
484+
485+
if (swipeVertical){
486+
relativeCenterPointInStripXOffset = centerPointInStripXOffset / pdfFile.getMaxPageWidth();
487+
relativeCenterPointInStripYOffset = centerPointInStripYOffset / pdfFile.getDocLen(zoom);
488+
}else {
489+
relativeCenterPointInStripXOffset = centerPointInStripXOffset / pdfFile.getDocLen(zoom);
490+
relativeCenterPointInStripYOffset = centerPointInStripYOffset / pdfFile.getMaxPageHeight();
491+
}
492+
477493
animationManager.stopAll();
478494
pdfFile.recalculatePageSizes(new Size(w, h));
495+
479496
if (swipeVertical) {
480-
moveTo(currentXOffset, -pdfFile.getPageOffset(currentPage, zoom));
481-
} else {
482-
moveTo(-pdfFile.getPageOffset(currentPage, zoom), currentYOffset);
497+
currentXOffset = -relativeCenterPointInStripXOffset * pdfFile.getMaxPageWidth() + w * 0.5f;
498+
currentYOffset = -relativeCenterPointInStripYOffset * pdfFile.getDocLen(zoom) + h * 0.5f ;
499+
}else {
500+
currentXOffset = -relativeCenterPointInStripXOffset * pdfFile.getDocLen(zoom) + w * 0.5f;
501+
currentYOffset = -relativeCenterPointInStripYOffset * pdfFile.getMaxPageHeight() + h * 0.5f;
483502
}
503+
moveTo(currentXOffset,currentYOffset);
484504
loadPageByOffset();
485505
}
486506

0 commit comments

Comments
 (0)