Dangling quote character in TextView - android

When I display quoted text in a textview, occasionally the wrapping will happen such that the final quote character (") is wrapped but nothing else is. So I wind up with a dangling quote as the last line, which doesn't look right.
Is there some property to set to keep the text together in these instances? My only thought would be that the period at the end of a quote would get marked as whitespace or the end of a word and so the ui feels free to wrap what comes after.

I was having a problem with dangling colon's in my TextViews, and this bit of code stopped them from wrapping:
tv.setEllipsize(null);
tv.setHorizontallyScrolling(true);
and my unverified stab at the equivalent xml:
android:ellipsize=0
android:singleLine="true"

Change the text font a half-size smaller or something similar to that. This could be an easy fix if not the best solution.

Related

Multi-Line TextView, but wrap second line

I have a brain picking problem that I am trying to solve for smart wrapping for TextView in Android. I have a LinearLayout (horizontal) that consists of TextView1, TextView2 and an ImageView. TextView1 can have long text or short text. For short text everything looks pretty neat and as expected. Like this -
Now the problem occurs when the text in TextView1 gets longer. Since maxLines for TextView1 is 2, it looks something like this
This is not an ideal experience because at many occasions there is a lot of white space text just lingering around in second line.
My ideal experience that I want is something like this -
Any ideas on how I can achieve this type of behavior? I have not written any code yet, because im not even sure how to go about doing it. Any help and pointers will greatly be appreciated. Hoping to get some answers from you all experts.
Edit 1: Adding screenshot based on Gavin's Flexbox suggestion
Sounds like an ideal case for FlexboxLayout. It acts like a LinearLayout but then wraps when it hits the end of a line.

Android create Spannable which does not wrap

I have a following issue with laying out text on Android. I'm basically trying to have two lines of text with minimal spacing and each should be styled differently. I've had quite good working solution with two singlelined TextViews one placed below the other, but I've been still getting a little bit cropped text on certain devices..
So I decided to switch to just one TextView an use Spannables instead which should be generally a better solution in all circumstances.
That means I needed to remove the single line property from my TextView -> in order to be able to wrap the line before starting the second Spannable..But there is an issue when is the text displayed at the first line actually longer than it..TextView wraps Automaticaly which is an unwanted behavior. Below you can see several screenshots, which should you better tell what I'm trying to achieve and where I'm now.
The first image shows new layout with spannables and you can see there the wrapped line as well.
The second image is the initial version of the layout woth two textviews layed out verically in a LinearLayout.
There is also a problem it's actually an appwidget, that means I do not have an access to that textview instance directly. I have been thinking about ditching textviews at all and instead use just ImageView and render all manually on canvas..That seems like an overkill to me, so I'm looking for a better solution. Unfortunately I'm kind of out of ideas and knowledge:)
Thank you
If you want to prevent a multi-word string from wrapping, you can replace the spaces with non-breaking spaces ('\u00A0'). TextView treats these as word characters, but renders them as spaces.

How to turn off textview whitespace trimming?

I want to display a string with leading whitespace in a Textview. But what I can see is that the android Textview is trimming all leading/trailing whitespace. Is there a way to turn this behavior off?
Old question but if you are not satisfied with "It Does Not trim itself." answer from comments this might help you.
If you are using resource strings with leading or trailing spaces, this is your issue: How to keep the spaces at the end and/or at the beginning of a String?
TextView indeed doesn't trim whitespaces but whatever reads strings from XML does. Use \u0020 instead of spaces.

Android TextView carry text by letters

Is there any way to carry text in TextView by letters in Android?
If no settings have been set – TextView carries text by words and situation is possible when with too long word you have big whitespace in TextView.
Example – what I’m talking about:
If you can get it at the TextView in XML, I would try giving it the attribute:
android:singleLine
If you have to do it in Java, there are a couple of options to keep it on the same line:
textView.setSingleLine();
textView.setTransformationMethod(new SingleLineTransformationMethod());
If you do want multiple lines, but you want it to break in a way that doesn't split it on the word, you might have to do it manually by analyzing the width of the TextView and how many characters can fit on a line, then inserting newlines appropriately. The two above methods will keep the contents of the TextView on one line, and it'll scroll horizontally. You can look into how this person is doing it.
Another option is to look into the android:ellipsize attribute, but I don't think it'll do what you're looking for.
Not sure if I understood correctly what you want, but I would guess.... if you would like to display the TextView in a single line, without "breaking" the sentence, you should add android:singleLine="true" to the TextView.
Otherwise, you may replace the "_" characters with space, in this case I believe it will carry the text, from the last space.

How to prevent words from breaking in textview when using wrap_content?

I am in the process of trying to convert a desktop app to Android - and am struggling with some very basic stuff.
When I specify a layout including a textview that holds a sizable amount of text wrap_content seems to arbitrarily break in the middle of a word and I can not find any documentation indicating this can be controlled.
Try useing Ellipsize property of TextView.
"If set, causes words that are longer than the view is wide to be ellipsized instead of broken in the middle"
Just posting this since none of the other solutions worked for me.
I had copied and pasted some text from online and I didn't realize it had weird spacing characters in that caused the text to wrap mid-word rather than at whitespace.
Here is the nasty character " " that looks like a space but isn't actually a space. I did a find and replace for this character and that solved my problem.

Categories

Resources