将html内容显示为动态的“页面" [英] Present html content as dynamic "pages"

查看:241
本文介绍了将html内容显示为动态的“页面"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Android构建电子书阅读器.电子书的内容通常分为带有一个或可能包含章节的html文件(epub).

I'm building an e-Book reader for android. The content of an ebook is often divided into html files (epub) with one or may chapters in them.

我打算建立一个电子书阅读器,将这些文件的内容分成不同的页面".问题是要知道一页上有多少文本适合"并计算正确的页面数量,因为这取决于许多不同的因素,例如:字体大小,字号,段落,图像,分页符,标题等.

I'm planning to build an e-book reader who divides the content of those files into different "pages". The problem is to know how many much text "fits" on one page and to calculate the correct amount of pages since that depends on a number of different factors, such as: font-size, word size, paragraphs, images, page-breaks, headlines etc.

理想情况下,我希望文本是可调整的并且可以选择,并且由于正常的TextView或EditText无法实现,因此我必须使用不可滚动的WebView.

Idealy i would have my text justified and selectable, and since that's not possible with normal TextView or EditText i must use a non-scrollable WebView.

因此,总而言之,我如何测量" WebView的一个页面"上适合的文本量?还是有另一种更好的方法来解决此问题?我看到Paint类支持度量文本和breakText.

So to sum it up, how can i "measure" how much text that fits on one "page" on my WebView? Or is there a different better approach to solve this? I saw that the Paint class as support for measure text and breakText.

谢谢!

推荐答案

注意:此答案未将网络视图用作您的显示表面.

您可以使用画布绘制每个页面.画布为您提供高度和高度.宽度,您可以使用该宽度使用

You can use the Canvas to draw each page. The canvas gives you it's height & width using which you can draw each line on the canvas using drawText based on the width & height available.

基本上,您可以计算一行中可以容纳多少个字母,可以选择多少个单词,请注意不要拆分任何单词并继续绘制文本.

Basically you can calculate how many letters can fit in a line , take that many words , taking care you don't split any words and keep drawing the text.

如果您将每个段落使用不同的工作程序的任务分拆了,您也可以使其速度更快.

If you break up the tasks to use different workers for each paragraph you can also probably make it fast.

这篇关于将html内容显示为动态的“页面"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆