首页 > 解决方案 > Android PDF scrollview 单连续页

问题描述

在xcode中,我可以将PDF显示为单个连续页面,PDF宽度等于屏幕宽度,然后垂直滚动是所述宽度的PDF高度。没问题

目前将相同的应用程序转换为 Android 并且在实现相同的 PDF 视图时遇到了一些困难

基本上我有一个很长的 PDF 页面(单页)。我不想在页面之间滑动,而是像在我的 iOS 应用程序中一样,让 PDF 文档填充 Android 屏幕宽度,然后垂直滚动以显示 PDF 的其余部分

我正在使用 com.github.barteksc.pdfviewer.PDFView 来呈现我的 PDF

在我的活动的 xml 中,我有:

<?xml version="1.0" encoding="utf-8"?>


<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true">

            tools:context=".ProfileActivity">

                <LinearLayout
                     android:layout_width="match_parent"
                     android:layout_height="match_parent"
                     android:orientation="vertical">

                        <com.github.barteksc.pdfviewer.PDFView
                             android:id="@+id/pdfView"
                             android:layout_width="match_parent"
                             android:layout_height="match_parent"/>
                 </LinearLayout>
</ScrollView>

我已经尝试将 scrollView、Linear 和 pdf 的 layout_height 更改为“wrap_content”,因为这看起来很合适,但是每当我这样做时,我都会得到一个空白屏幕。似乎这样做会导致没有高度属性,因此视图完全折叠

我得到:安卓屏幕

我想要的是:iOS 屏幕 - 滚动显示 PDF 的其余部分

真的很感激任何进一步的帮助,这真的是我唯一的症结所在。我希望android有PDFKit(类似),因为我发现它很容易使用和实现

标签: javaandroidpdfscroll

解决方案


嗯,有答案!

我不得不“升级”到最新版本:3.1.0-beta.1 并使用:

.pageFitPolicy(FitPolicy.WIDTH)

结合我的 XML:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">
        tools:context=".AboutActivity">

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:orientation="vertical">

    <com.github.barteksc.pdfviewer.PDFView
            android:id="@+id/pdfView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
</LinearLayout>
</ScrollView>

工作完美。我希望这对其他人有帮助


推荐阅读