开发者

ListView with maybe more than 1 line

I want to create a list view which contain TextViews that are built from conceptually separate strings.

Some list items may have 1 line; others might have more than 1 line, for example: Comment name = "alice", and comment text is a long string of text that must be wrapped to multiple lines:

alice commenttttttttttttttttttttttttttttttttt 

      ttttttttttttttt

but I want it to show:

alice commenttttttttttttttttttttttttttttttttt 

ttttttttttttttt

How to set the la开发者_如何学运维yout ?


Rather than use two TextView in your layout, just use a single layout, built from your 2 source strings:

txt1.setText(comment.postedBy + " - " + comment.text);

It is not possible using the idiomatic Android ViewGroup layouts (e.g., RelativeLayout, LinearLayout, etc) to have the 2nd view ("commentttt..." in your example) both: a) "word-wrap" to a second line, and b) "float" around the first view ("alice" in your example). The only way to achieve that type of flowing layout is to combine the two strings into a single TextView. If you want varying styles as well, you can use something like Html.fromHtml(String) to parse things like "<b>This is bold</b> and this is not." There are other Span types that you can apply to text as needed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜