How to use WebView to display html pages in ebook reader fashion?


I have a collection of html files on my android device. I need to display them in my application in a special way: I want to split long pages to few smaller pieces, so they could fit to the device height. I am not sure is it possible to achieve this with the built-in facilities. What can I do with this problem?


You probably should not be using a webview here.

Try the following approach :

You can use the Canvas to draw each page. The canvas will give you it’s height & width. Using this you can draw each line on the canvas using Drawtext based on the width & height which are available.

So you would basically be calculating 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. Also you could use different worker threads to work on different paragraphs to make the rendering faster.

Hope this helps!!!!

Answered By – Abhishek Sabbarwal

Leave a Comment