app实现预览功能
所花时间:2小时
代码量:如下:
博客量:本学期截至目前42篇
了解到的知识点:app预浏览
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <?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> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | 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, OnLoadCompleteListener, 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) { } } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)