gpt4 book ai didi

java - Android PDF ScrollView 单个连续页面

转载 作者:行者123 更新时间:2023-12-02 09:46:20 31 4
gpt4 key购买 nike

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

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

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

我正在使用 com.github.barteksc.pdfviewer.PDFView 来渲染我的 PDF

在我的 Activity 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”,因为这看起来很合适,但每当我这样做时,我都会得到一个空白屏幕。看来这样做会导致没有高度属性,因此 View 完全折叠

我得到:Android screen

我想要的是:iOS Screen - which scrolls to show rest of PDF

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

最佳答案

好吧,有一个答案!

我必须“升级”到最新版本: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>

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

关于java - Android PDF ScrollView 单个连续页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56618081/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com