最近在做一个健康类项目,要求用pdf展示体检报告,ios webview支持展示pdf,android的不支持,后来只能把pdf下载下来,再在程序中嵌入pdf查看,本来采用pdfViewer,但是发现有的pdf会报错,不稳定,上网搜了好久,也没有解决方案,后来换成了mupdf,按理说应该去github找star和fork最多的,说得好有道理的样子,我就是这样做的,然而还是没有解决,后来google到了一个帖子,说这个可以,下面进入正题,上链接:
https://github.com/geek5nan/AndroidMuPDFDemo
这个是可以解析pdf的但是项目要求pdf上下滑动翻页,但这个项目是左右滑动的,别着急,博主有办法:
将项目中onLayout2方法换成下面这个
protected void onLayout2(boolean changed, int left, int top, int right, int bottom) {
// super.onLayout(changed, left, top, right, bottom);
// "Edit mode" means when the View is being displayed in the Android GUI
// editor. (this class
// is instantiated in the IDE, so we need to be a bit careful what we
// do).
if (isInEditMode())
return;
View cv = mChildViews.get(mCurrent);
Point cvOffset;
if (!mResetLayout) {
// Move to next or previous if current is sufficiently off center
if (cv != null) {
cvOffset = subScreenSizeOffset(cv);
// cv.getRight() may be out of date with the current scale
// so add left to the measured width for the correct position
// if (cv.getLeft() + cv.getMeasuredWidth() + cvOffset.x + GAP/2
// + mXScroll < getWidth()/2 && mCurrent + 1 <
// mAdapter.getCount()) {
if (cv.getTop() + cv.getMeasuredHeight() + cvOffset.y + GAP / 2 + mYScroll < getHeight() / 2
&& mCurrent + 1 < mAdapter.getCount()) {
postUnsettle(cv);
// post to invoke test for end of animation
// where we must set hq area for the new current view
mStepper.prod();
onMoveOffChild(mCurrent);
mCurrent++;
onMoveToChild(mCurrent);
}
// if (cv.getLeft() - cvOffset.x - GAP/2 + mXScroll >=
// getWidth()/2 && mCurrent > 0) {
if (cv.getTop() - cvOffset.y - GAP / 2 + mYScroll >= getHeight() / 2 &a