在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”,这似乎很合适,但是每当执行此操作时,我都会得到一个空白屏幕。似乎这样做导致没有height属性,因此视图完全折叠
非常感谢您提供进一步的帮助,这确实是我唯一的坚持。我希望android具有PDFKit(类似),因为我发现它非常易于使用和实现
答案 0 :(得分:0)
有一个答案!
我必须“升级”到最新版本: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>
工作完美。我希望这对其他人有帮助