<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout 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:background="@color/white" android:padding="@dimen/box_inset_layout_padding" tools:context=".activity.PdfActivity"> <com.github.barteksc.pdfviewer.PDFView android:id="@+id/pdfView" android:layout_width="match_parent" android:layout_height="match_parent"/> </androidx.constraintlayout.widget.ConstraintLayout>
package com.example.nucleicacid32.activity; import android.graphics.Canvas; import android.os.Bundle; import android.os.StrictMode; import com.example.nucleicacid32.base.BaseActivity; import com.example.nucleicacid32.databinding.ActivityPdfBinding; import com.github.barteksc.pdfviewer.listener.OnDrawListener; import com.github.barteksc.pdfviewer.listener.OnLoadCompleteListener; import com.github.barteksc.pdfviewer.listener.OnPageChangeListener; import com.github.barteksc.pdfviewer.listener.OnPageErrorListener; import com.github.barteksc.pdfviewer.scroll.DefaultScrollHandle; public class PdfActivity extends BaseActivity<ActivityPdfBinding> implements OnPageChangeListener, onl oadCompleteListener, OnDrawListener, OnPageErrorListener { public static final String FILE_NAME = "ali.pdf"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); init(); } private void init() { if (android.os.Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); } viewBinding.pdfView.fromAsset(FILE_NAME) .defaultPage(0) .onPageChange(this) .enableSwipe(false) .enableAnnotationRendering(true) .onLoad(this) .scrollHandle(new DefaultScrollHandle(this)) .spacing(10) // in dp .onPageError(this) .load(); } @Override public void onPageChanged(int page, int pageCount) { } @Override public void loadComplete(int nbPages) { } @Override public void onLayerDrawn(Canvas canvas, float pageWidth, float pageHeight, int displayedPage) { } @Override public void onPageError(int page, Throwable t) { } }
标签:功能,barteksc,pdfviewer,预览,app,void,import,com,public From: https://www.cnblogs.com/nanbei666/p/17316738.html