在android中渲染epub书?
我尝试在 android pad 中显示 epub 书。我可以解析html和css,以显示书的内容和格式,也许书包含图片,看来我有两个选择:
- 使用Webview。
- 编写一个客户视图,以便它可以渲染 html/css --- 这似乎是一个非常复杂的任务。
哪个是好方法?如果我必须使用WebView,那么分页逻辑怎么样,因为webview在一页中解析一个html文件,所以我在webview中找不到分页符。
I am try to show epub book in android pad. I can parse the html and css, in order to show the book's content and format, perhaps the book include pictures, It seems that I have two option:
- use Webview.
- Write a customer view, so that it can render html/css --- it seems a very complicated task.
Which is the good way? If I have to use WebView, how about the page break logic, since webview parse one html file in one page, I can not find the page break in webview.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我已经为 android 和 ios 开发了一个原生 epub 播放器
我在这里分享的代码是我的产品源代码的一部分,复制和粘贴它对你不起作用。当作参考吧。
我在android中使用了webview,在ios中使用了uiwebview来制作自定义视图并解析
html/css
几乎就像开发一个新的渲染引擎(即浏览器)一样。这是一个繁琐而复杂的过程。简而言之,我向您介绍我在 android 中遵循的步骤
客户端(WebViewClient、WebChromeClient)代码:
将 jquery.js 注入 webview:
假设一个 .html 文件有 3 个页面的内容 - 前一个 webview 是第一页,当前 webview 是第二页,下一个 webview 是第三页,但所有 webview 加载相同的 url。但它们的内容偏移量不同。
代码:
无需使用任何第三方库。只需花费大量时间编写自己的所有内容即可。
I have developed a native epub player for android and ios
Code I shared here is part of my product source code, copying and pasting of it will not work for you. Consider it as reference.
I have used webview in android and uiwebview in ios making custom view and parsing
html/css
is almost like developing a new rendering engine (i.e browser).Its a tedious and complex.Briefly I give you the steps I have followed for android
Code:
Inject jquery.js into webview:
lets say one .html file has content of 3 pages - previous webview is first page,current webview is second page,next webview is third page but all webviews loaded the same url.But their content offset is different.
Code:
No need to use any third party libs .Just need to spend good amount of time to write every thing your own.
不错,但有问题......:-)
我认为 android webview 没有任何分页逻辑可用,根据您的关注,WebView 是显示 .epub 文件的不错选择(您可以添加许多功能,例如,突出显示、搜索、书签等..)。如果您发现了这一点,那么如果设备尺寸发生变化怎么办?我所做的是,我只是在 webview 中显示网页并禁用滚动,然后我可以找到 webview 的最大高度和设备屏幕尺寸(高度和宽度),现在我为下一页和上一页放置了两个按钮,这只是根据设备尺寸的高度滚动页面..
简单的事情..如果你想尝试这个...(这是我个人的观点,可能我在这方面是错的)
Nice One, But in Question... :-)
I don't think any Page Break logic for android webview is available, As per your concern WebView is the good choice to display .epub file (You can add many functionality like, highlight, search, bookmark etc..). And If you found that one then what about if device size is changed. What I am doing is, I just display WebPage in webview and disable scroll, Then I can find the max height of webview, and device screen size (Height and width), Now I have put two buttons for next and previous pages, which just scroll page according to height of device size..
Something easy.. Try this if you want to... (This is my personal opinion may be I am wrong on this)
有一个 javascript 库可以解决分页问题
http://monocle.inventivelabs.com.au/
这个项目在android中使用它
https://github.com/sharathpuranik/chaek-android
获取源代码并查看一下。
There's this javascript library that takes care of the pagination issue
http://monocle.inventivelabs.com.au/
This project uses it in android
https://github.com/sharathpuranik/chaek-android
Grab the sourcecode and take a look.