Multi-Line TextView, but wrap second line - android

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.

Related

Is there a way to change how the Android EditText highlight behaves?

I have my EditText view looking almost the way it's supposed to look. However, since the text's gravity is set to "center", the highlight behaves a little different than I would expect if it spans more than one line. Take a look:
I wonder if it's possible for the highlight to look more like this (edited in photoshop):
As an added bonus, if there is a way to have the beginning pink handle line up properly with the first word, that would be great. As you can tell from the first image, it's offset downwards and looks broken.
Thanks

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.

¿Is it possible to put an icon with an action inside of EditText?

I'm looking forward to create an EditText with an Icon on the right that has some kind of functionality.
I've seen that the Google IO 2013 app has something like that on the search widget.
I want to know if its possible to do that with a simple EditText.
I've tried with a simple ImageView on the right of the EditText, but it looks really bad.
I would really appreciate if someone could point me in the right direction.
Thanks.
EDIT 1
This is an example of what I want. It looks really good. I have used the drawableRight and it doesn't look this good.
http://img836.imageshack.us/img836/1521/6faa.png
EDIT 2
I managed to build something that looks really similar to the SearchWidget with the voice recognition option.
I put two EditText next to each other (with a RelativeLayout), and set the margin left for the one on the right to -10dp. This way it looks like one EditText. I know this is not proper, but right now does what I want.
My problem now is the image, I'm using a 32x32 px image, because it fits fine, but it has really low quality, I'll look into that.
http://img560.imageshack.us/img560/9394/ilwp.png
You can definitely use a custom EditText with drawableRight as follows:
android:drawableRight="#drawable/your_drawable"
Refer
1.Custom EditText- 1
2.Custom EditText- 2

Pocket-like TextView automatic spacing based on TextView width?

This is quite hard to understand, but I'm trying to find out how to make a TextView adapt to change the text spacing between words on a line which allows the text to reach the very right side of the TextView.
Consider this as an example (this should get my point across):
This one is a line of text which fills the view itself
This is another that does the same thing
How would I go about making my text react like this? An example application which does this is Pocket, so I know it can be done - I just don't know how.
Any help is appreciated!
What you're referring to is called text justification and is something that has been discussed more than once here on SO in the context of Android.
The short answer is that, unfortunately, justification is currently not (natively) supported by the TextView widget. There are however workarounds that involve either:
Manipulating the text in the TextView in such a way that the result is visually close to that of justification. Example.
Using a WebView to render the text. Example.
Justifying text on a web page is trivial, but the WebView is a more heavyweight component than a TextView, and hence the feature will come with a performance penalty.
Note that I don't know what approach Pocket is using for their articles, but there are ways to figure that out, and they're not too complicated. That's a completely different can of worms though, so I'll leave it at that.

Set the textView visible to the top of the containing text (scrollable textView)

Sorry for the bad title, but I don't speak very well english. My problem (I'm working on since 2 hours) is just a detail but I want to know how to solve it, and this could help someone in the future.
I've already searched on StackOverflow and other websites, but i don't find the solution to my problem, so there it is :
I have a textView, I make it scrollable using this (second line) :
textViewDesc = (TextView) findViewById(R.id.textViewDesc);
textViewDesc.setMovementMethod(new ScrollingMovementMethod());
and I use these attributes of the xml file :
android:scrollbars="vertical"
android:maxLines="100"
When I push my button on my app, it searches text from the internet and put it into my TextView. This works well, but the "failure" is the TextView starts not with the beginning of the text, but it finish with the end (I don't see the beginning, i have to scroll it).
And i think it's not obvious to a people using my app that he has to start scrolling to the top of the textView before starting his reading.
I hope you understand my problem, and help me to fix this.
Thank you in advance
What about textViewDesc.setScrollY(0) ?
Also, I've noticed that TextView scrolling is pretty unreliable. What about putting your TextView inside a ScrollView instead? (http://developer.android.com/reference/android/widget/ScrollView.html)

Categories

Resources