简体   繁体   中英

Android PDF scrollview single continuous page

In xcode I can display a PDF as a single continuous page, with the PDF width being equal to screen width and then the vertical scroll being the height of PDF for said width. No problems

Currently converting same app to Android and having some difficulty implementing same PDF view

Basically I have a PDF page that is very long (single page). I don't want to swipe between pages, but instead like in my iOS app, have the PDF document fill the Android screen width wise, and then scroll vertically to show rest of PDF

I'm using com.github.barteksc.pdfviewer.PDFView to render my PDF

In my xml for the activity I have:

<?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>

I've tried changing the layout_height to "wrap_content" for scrollView, Linear and pdf, as that would seem appropriate, but whenever I do this I get a blank screen. It seems that doing so resulting in no height attribute so the view collapses completely

I get: Android屏幕

What I want: iOS屏幕 - 滚动显示其余PDF

Would really appreciate any further help, this is really my only sticking point. I wish android had PDFKit (similar) as I found that quite easy to use and implement

Well there is an answer!

I had to 'upgrade' to the latest version: 3.1.0-beta.1 and use the:

.pageFitPolicy(FitPolicy.WIDTH)

Combined with my 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>

Worked perfectly. I hope this helps others

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM