3

I'm using the method given in Android HTML ImageGetter as AsyncTask to load images into a Textview from an html source. This works great, and doesnt freeze the UI while downloading the images. The problem I'm having, is that when it gets the images, an draws them into the TextView, the TextView isnt resizing, so the images appear over the text already there, an in fact are truncated to the current size of the TextView (set with wrap-content) if there are many images.

I cant set the initial size of the TextView specifically, as I dont know in advance if there will be images, or how many, or what size. Any suggestions on how I can resize the TextView after the images have loaded?

The TextView is in a ListView handled by a custom adapter if that makes any difference.

Oh,and the reason I dont just use a WebView, is that as its in a custom row ListView, there can be up to 20 of the rows, and I was having weird problems with that many WebViews being handled at once.

Thanks

Community
  • 1
  • 1
Kevin Appleyard
  • 149
  • 2
  • 8
  • Why arent you using imageView instead of TextView? – coder_For_Life22 Dec 12 '11 at 21:27
  • I'm not using ImageView because the html also contains a bunch of text that I need to display. The text being the main part, but with optional images included. – Kevin Appleyard Dec 12 '11 at 21:31
  • Soo...Why arent you parsing the Text and then downloading the images to a imageview? It may make life easier for you. – coder_For_Life22 Dec 12 '11 at 21:34
  • Ok, so I think you may be right, I think this means I have to: 1) parse out the image links (jsoup I guess). 2) programatically add between 0 and many ImageViews to my custom adapter row for the ListView. 3) implement an async downloader for the various ImageViews. And the TextView is so close to working *sigh* :) – Kevin Appleyard Dec 12 '11 at 22:53

2 Answers2

0

Try this, should work.

For example:

(TextView).setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAPֹ_CONTENT, LayoutParams.WRAP_CONTENT));
Community
  • 1
  • 1
Jong
  • 9,045
  • 3
  • 34
  • 66
  • Tanks for the suggestion, the code in the link I posted calls Invalidate on the container (passed as a param) an that doesnt seem to work, I've tried this too, and still no luck. (Changed the layout type to Relative as thats what the TextView is contained within). – Kevin Appleyard Dec 12 '11 at 22:20
  • 1
    Bingo, think I've got it. Instead of passing the TextView object to the URLImageParser class as a View, pass it specifically as a TextView. This then allows me to call `URLImageParser.this.container.setEllipsize(null);` on it, which seems to do the job. Posting this as a comment as it wont let me post as an answer to my own question yet. Will update the question with this answer later. – Kevin Appleyard Dec 12 '11 at 23:32
  • This seems like a good approach. I think the way i posted in the comment is less problematic approach, and is more detailed. – coder_For_Life22 Dec 13 '11 at 01:13
0

Bingo, think I've got it.

Instead of passing the TextView object to the URLImageParser class as a View, pass it specifically as a TextView. This then allows me to call URLImageParser.this.container.setEllipsize(null); on it, which seems to do the job.

Kevin Appleyard
  • 149
  • 2
  • 8
  • 2
    The `URLImageParser.this.container.setEllipsize(null);` solution works fine for Android 2.x but not for Android 4.x!!! Someone have an idea? –  Mar 17 '12 at 13:07