A work around I can think off the top of my head and from previous issues with TextView
formatting, the best way is to have, say, a RelativeLayout
, and just place 3 separate Views inside of it. It will represent the TextView
that is right next to the image, the ImageView
itself next to the text, and then the last TextView
under the first text, but with the layout_width="match_parent"
. There is no other way to do this with the TextView
or ImageView
otherwise.
EDIT:
The only other workaround I believe you can do if you are so intent on using 1 TextView, I would suggest using SpannableStringBuilder
with SpannableString
. I didn't originally give you that as an option for a specific reason. If you go back to that link you posted on your question, one of the answers say they found an answer. I believe that person linked to a good resource, but they are wrong for what your needs are. When using SpannableStringBuilder
, you are essentially creating a string that can have potentially many different version of a single string into one, like 3 different colors on a single string, or strings with 3 different sizes, all in one TextView
. Like what you need.
Now the link talks about putting an image and having the text wrap around it nicely, but its not that simple, and that example isn't what you need. What you could do to provide it all in one TextView
is to add line breaks after the first few lines where you know the image will be to the right, and then not do so after the image. But the thing is it still needs to go in a RelativeLayout
. But instead of two TextViews you only need one. Just place the TextView at the top left of whatever the parent is and the ImageView to the top right of whatever the parent is. This simulates a floating
element. But I think doing it that way is more trouble than its worth. It really is because you have to do calculations to figure out where to put the line breaks, etc. You are better off using two TextView
s in which to make it look like you need. So in my opinion, DO NOT USE SpannableStringBuilder
, but if you do not mind trying to figure out all that spacing, that does give you what you need with a single TextView.