java - 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”,因为这看起来很合适,但是每当我这样做时,我都会得到一个空白屏幕。似乎这样做会导致没有高度属性,因此视图完全折叠
真的很感激任何进一步的帮助,这真的是我唯一的症结所在。我希望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>
工作完美。我希望这对其他人有帮助
推荐阅读
- mule - 在 mule4 中打开 API 规范到 Odata raml 转换
- ios - 分段错误:11,xcode -12
- python - FastAPI:检索 jinja2 `url_for` 的端点以提供跳转链接
- c# - 当涉及高速网络消息传递时,使用易失字典是一个不错的选择吗?
- javascript - 渲染子菜单的问题对于 React JS 中的 infiinit 下拉菜单
- python - PyInstaller & NSIS Zip2Exe - 在你的电脑之外引用文件
- r - 将跨距离矩阵从“Crossdist”类转换为矩阵
- r - 通过取平均值来组合具有相似名称的列
- macos - 无法通过 SSH 获取钥匙串密码
- google-apps-script - 根据用户输入将数据从 Google 表格中提取到 html 页面