pdf阅读器框架
implementation 'com.github.barteksc:android-pdf-viewer:2.7.0-beta.1'
layout
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bg_f3f3f3"
android:orientation="vertical">
<com.github.barteksc.pdfviewer.PDFView
android:id="@+id/pdfView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/page"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:layout_margin="5dp"
android:text="" />
</FrameLayout>
使用
//继承相关接口
public class PdfViewActivity extends BaseActivity
implements PdfViewActivityContract.View, OnPageChangeListener
//KEY_URL下载好的pdf地址
File file = new File(KEY_URL);
if (file.exists()) {
pdfView.fromFile(file)
.enableDoubletap(true)
.defaultPage(0)
.swipeHorizontal(true)
.enableSwipe(true)
.onPageChange(this)
.load();
}
//页码显示
@Override
public void onPageChanged(int i, int i1) {
tvPage.setText((i + 1) + "/" + i1);
}