简体   繁体   English

Android PDF scrollview单连续页面

[英]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. 在xcode中,我可以将PDF显示为单个连续页面,PDF宽度等于屏幕宽度,然后垂直滚动是所述宽度的PDF高度。 No problems 没问题

Currently converting same app to Android and having some difficulty implementing same PDF view 目前正在将相同的应用程序转换为Android,并且在实现相同的PDF视

Basically I have a PDF page that is very long (single page). 基本上我有一个很长的PDF页面(单页)。 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 我不想在页面之间滑动,但是在我的iOS应用程序中,让PDF文档明智地填充Android屏幕,然后垂直滚动以显示其余的PDF

I'm using com.github.barteksc.pdfviewer.PDFView to render my PDF 我正在使用com.github.barteksc.pdfviewer.PDFView来呈现我的PDF

In my xml for the activity I have: 在我的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>

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. 我已经尝试将layout_height更改为scrollView,Linear和pdf的“wrap_content”,因为这似乎是合适的,但每当我这样做时,我得到一个空白屏幕。 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 我希望android有PDFKit(类似),因为我发现它很容易使用和实现

Well there is an answer! 那么有答案!

I had to 'upgrade' to the latest version: 3.1.0-beta.1 and use the: 我不得不'升级'到最新版本:3.1.0-beta.1并使用:

.pageFitPolicy(FitPolicy.WIDTH)

Combined with my XML: 结合我的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 我希望这有助于其他人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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