views:

25

answers:

1

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?

A: 

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.

CommonsWare
I've considered The Html/TextView option and tried it, but I've been pretty disappointed at the level of HTML support it provides. Things like <pre> tags (which are pretty essential for my use) are haphazardly supported at best, and other tags are ignored completely. I'm pretty sure I even noticed it giving me italics for a <b> tag once. In short, unless there's a way to improve the rendering support it provides I don't think that Html.fromHtml() is going to be sufficient.
Toji
So after a bit more playing the correct answer here is, really, to choose some other UI model. I'm not super happy about that, but the WebView just isn't designed for use is a scrollview. (or, more accurately, scrollviews aren't designed for widgets that do their own scrolling.)
Toji