spanned

Remove extra line breaks after Html.fromHtml()

痞子三分冷 提交于 2019-11-28 17:28:01
I am trying to place html into a TextView. Everything works perfectly, this is my code. String htmlTxt = "<p>Hellllo</p>"; // the html is form an API Spanned html = Html.fromHtml(htmlTxt); myTextView.setText(html); This sets my TextView with the correct html. But my problem is, having a tag in the html, the result text that goes into the TextView has a "\n" at the end, so it pushes my TextView's height higher than it should be. Since its a Spanned variable, I can't apply regex replace to remove the "\n", and if I was to convert it into a string, then apply regex, I lose the functionality of

How to loop through the spans in a SpannedString or SpannableString in Android

久未见 提交于 2019-11-27 22:21:32
问题 If I have a SpannedString (or SpannableString ) like this SpannableString spannableString = new SpannableString("Hello World!"); ForegroundColorSpan foregroundSpan = new ForegroundColorSpan(Color.RED); BackgroundColorSpan backgroundSpan = new BackgroundColorSpan(Color.YELLOW); spannableString.setSpan(foregroundSpan, 1, 8, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); spannableString.setSpan(backgroundSpan, 3, spannableString.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); textView.setText

Remove extra line breaks after Html.fromHtml()

可紊 提交于 2019-11-27 10:17:20
问题 I am trying to place html into a TextView. Everything works perfectly, this is my code. String htmlTxt = "<p>Hellllo</p>"; // the html is form an API Spanned html = Html.fromHtml(htmlTxt); myTextView.setText(html); This sets my TextView with the correct html. But my problem is, having a tag in the html, the result text that goes into the TextView has a "\n" at the end, so it pushes my TextView's height higher than it should be. Since its a Spanned variable, I can't apply regex replace to

Android ImageGetter images overlapping text

流过昼夜 提交于 2019-11-27 06:59:45
I'm trying to load a block of HTML into a TextView, including images, using URLImageParser p = new URLImageParser(articleBody, this); Spanned htmlSpan = Html.fromHtml(parsedString, p, null); parsedString is the HTML, by the way. Anyway, it loads up, but the images aren't having any space created for them to sit in, so they end up overlapping the text above them. Here's my URLImageParser file: public class URLImageParser implements Html.ImageGetter { Context c; View container; /*** * Construct the URLImageParser which will execute AsyncTask and refresh the container * @param t * @param c */

Android ImageGetter images overlapping text

别说谁变了你拦得住时间么 提交于 2019-11-26 17:36:27
问题 I'm trying to load a block of HTML into a TextView, including images, using URLImageParser p = new URLImageParser(articleBody, this); Spanned htmlSpan = Html.fromHtml(parsedString, p, null); parsedString is the HTML, by the way. Anyway, it loads up, but the images aren't having any space created for them to sit in, so they end up overlapping the text above them. Here's my URLImageParser file: public class URLImageParser implements Html.ImageGetter { Context c; View container; /*** * Construct