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?
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.
Related
I've two textviews aligned horizontally. when the second TextView becomes longer it wraps to the next line incorrectly. I want it to start the text from the beginning of the layout instead of just below the TextView.
I've tried flow layout but it wrap all the text to the bottom rather than wrapping just the additional text.
What I want :
The reason I want two TextView is because I'm working on Drag and Drop quiz, so when the user drags the answer to the textview it will change it's content "setText(answer)" to be the answer.
Thank you for helping
Drag and drop image
I don't think that this is possible. You can always use string with arguments to achieve that.
e.g.
<string name="test_string">%1$s %2$s</string>
and then
getString(R.string.test_string, "text view one text", "text view two text")
I'm not sure this is possible. It sounds like an awkward way of going about something quite simple.
My solution would be to have 1 TextView, and join the two strings together that would otherwise be in separate TextViews.
Instead of two textViews, take two string variables and work on them. in the end, just concatenate two strings and display it in the textView.
In order to give it look and feel of two different textViews, you can either use html format, or spannable text.
We might be able to help understand your problem better if you can explain the actual scenario, and why two textViews are necessary.
There is compound drawable option in TextView to avoid using a parent ViewGroup and an ImageView next to TextView. Which is neat and faster in performance as said by lint. I'm trying to do something similar. A TextView with 2 texts inside, one aligned to left, one aligned to write. Sounds strange but it will only allowed for single line TextView.
And to do that, I can extend TextView and set its gravity to right side. And inside onDraw let the super class draw on right side, and then draw text on left side.
Problem is, I'm not really sure about all this. My question is, will there be a big performance difference ? I dont have any slower device to test. I will be using this TextView inside an item layout of GridView, Item layout already have many views, it would be nice if I could merge some views to one. But again, will there be a performance difference, like noticeable by user ? And if there will be, the approach I will be using by extending the TextView, is there any problem or I should try some other way ?
Thank you
From what I have read I would imagine that you are using a custom adapter for your GridView?
If so, cant you just use TableRow and insert 2 TextViews inside that with each layout weight set to 1. Then you will have 2 columns in one row?
Just an idea.
I am making a calendar. Each day is a textview with a number denoting the day of the month.
I'd like to overlay another view which signals that there is an event on that date. See below image or think about how the google calendar app looks. How do I do this?
One way is to make the two textview inside a Relative Layout or a Frame Layout. You can look at this for reference.
You could use a TableLayout to store the TextViews in rows and colums.
A possible way of marking a special day would be changing the background resource of the specific cell with one that has a marking on it, that does not overlap with the number.
If you want more fancy stuff, you could write your custom View subclassing TextView, which handles its onDraw calls and everything else.
As far as I know you can use a RelativeLayout to overlap views.
You can try setting left drawable (android:drawableLeft="") to the TextView. OR, you can use some transparent background images with indicators drawn in top-left.
I have a multi-line text view that can get quite large. When the user is actually editing it I want to expand as needed -- but then collapse it again down to a single line when it's no longer being edited.
Example: During the edit the textview may have many lines and look like this
Lots of really long notes
on multiple liness
When focus is lost, I want to contract the view back to single line so that look like:
Lots of really long...
Any suggestions?
There have been several questions like this one, please check here:
TextView expand animation like in Android Market
Android: Expand/collapse animation
Android EditText won't take up remaining space
How to scale/resize text to fit a TextView?
Some of these links include the sliding animation for the textviews. I hope this helps!
Regards,
Tried wrapping it inside a ScrollView?
I am trying to make a sentence-filling like interface, where I can have TextViews and EditTexts mixed arbitrarily in a paragraph.
I have had a look at this question, but the problem was that when I have [ TextView1, EditText, TextView2 ] and the content of TextView1 consumes 1 full line and 1 fifth of the second line, then TextView1 will have to span the entire width because it is a rectangle. This pushes EditText to the next line, which is ugly.
So is it possible to create such kind of ViewGroup/Layout from existing stuff in Android, or I'd have to make a custom View from scratch?
In case I'm too bad at explaining, this screenshot describes my problem:
Thank you very much.
I think there's some work here :)
You should make two text views - one for line 1, one for line 2. Estimate the text, that fits on the first line, put it in the first text view. Put the rest in the second line, and it'll fit just nice.... I think you know this, and I doubt there is an easier way to do this :)
It's a nice task anyway.
Greets,
Danail