SDHtmlTextView
SDHtmlTextView copied to clipboard
HTML tables rendering issue
Hello,
HTML tables do not seem to be correctly rendered. I see 2 major issues when you have more than 1 line:
- A space is added between each row
- The last row is repeated. Let's say you have 6 rows in your table, you will see 6 rows, but the last row will be repeated multiple times, replacing the rows that should be displayed.
There is also an issue where table header is not centered horizontally.
In the screenshot below, you will see 3 components in that order: a webview, a textview using the native HTML.fromHtml method, a text view using htmlSpanner.

Otherwise the library works great, but without tables support unfortunately webview is the only alternative and it's not as fast and lightweight as a TextView.
Hi, the issue has been fixed in this pull request https://github.com/SysdataSpA/SDHtmlTextView/pull/11 that will be merged soon.
Great :) I will let you know how that works out for me. Thanks a lot for the quick fix.
On a side note, how do I get the latest build from Gradle as I don't see any release on this page? So far I have been using the instructions on this page: https://android-arsenal.com/details/1/6563#!package
Is there a better way?
Just check the readme section https://github.com/SysdataSpA/SDHtmlTextView#usage dedicated to usage and installation
Thank you. Problem solved.
As for the additional lines and space at the bottom, I simply removed both the "builder.append("\n");" in the TableHandler.handleTagNode method and they are gone. I have the same issue with lists, I guess it can be resolved the same way.
With the lists I don't see any issue in my sample app. Can you give me more info about that?
Here are 2 screenshots. One for tables, one for lists. On each screenshot you have a webview, a textview using the native Html.fromHtml method and a textview using this library.
HTML code:
HTML code:
<table
border="1" style="border-collapse: collapse"><th colspan="5">Header</th></tr></thead><tbody><tr><td>A1</td><td>A2</td><td>A3</td><td>A4</td><td>A5</td></tr><tr><td>B1</td><td>B2</td><td>B3</td><td>B4</td><td>B5</td></tr></tbody></table>
<ul style="margin-bottom:0;"><li>item 1</li><li>item 2</li><li>item 3</li></ul>
Hello @sranieri. An issue I encountered with your fix is that if you reuse the htmlspanner for multiple values, the first row will always be centered if it has ever been once. To fix this I added "hasHeader = false;" at the beginning of the handleTagNode method in TableHander.