HTML formatted content in a ScrollView
-
27-09-2019 - |
문제
I'm trying to put together an Android view that has several elements stacked on top of one another. Some of these elements need to have HTML formatting applied, and I plan to stack enough of them that they will run off the screen, requiring a ScrollView. As an example, I would expect the layout to look something like this:
<ScrollView>
<LinearLayout vertical>
<TextView />
<Button />
<Html />
<TextView />
<Button />
<Html />
Etc...
</LinearLayout>
</ScrollView>
The obvious choice up front for the HTML portion is a WebView, since it renders everything exactly as I would want to see it, but the problem is that the WebView begins to fall apart when used in a ScrollView. It's difficult to get it to even show up without some manual refreshing.
Given that, what would be the most effective way to display this type of content?
해결책
Option #1: As Sameer Segal indicates, use Html.fromHtml()
and TextView
.
Option #2: Render the whole thing in HTML. There is nothing particularly magic about Android TextView
and Button
.
Option #3: Choose some other UI model that would eliminate the need for the ScrollView
.