wrap text view around img view
Asked Answered
S

1

3

Good evening,

I am trying to wrap my text around an image view like the question is asking here:

Textview wrap around View

in landscape.

but I wish to not do it in HTML / CSS. plus, that question is 2 years old. I am hoping someone has figured out a work around with this.

Also, I wish to keep my portrait view the way it is with the img view under the text view i.e. no wrapping.

Can anyone help me?

Sherikasherill answered 9/8, 2012 at 0:55 Comment(1)
I just found this: code.google.com/p/android-flowtextview Which basically does what the accepted answer suggests but in ready-to-use widget form.Veratridine
N
0

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 TextViews 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.

Nihi answered 9/8, 2012 at 2:27 Comment(3)
I want my text to flow, not be divided up between 2 textview.Sherikasherill
If you read my answer correctly, there is no way to accomplish this using TextView alone. It won't "flow" on its own unfortunately. There is also not an attribute that will make it do so. What you are asking is to make TextView text wrap around the ImageView like a floating image in HTML. Doesn't exist in Android XML. All you can do is hacky workarounds like mine or even something else you come up with.Nihi
Ok @Sherikasherill I added some info for you that I didn't at first because I do not believe it is your best options. But hey, its your app. So if it helps, accept the answer :)Nihi

© 2022 - 2024 — McMap. All rights reserved.