I have a needs to limit the length of a textview to a certain number and then make the text wrap. Unfortunately using maxLength will only "crop" the text and won't make it wrapping like it should be even when using android:layout_width="wrap_content". How to achieve this feature?
Add this to your text view,
android:layout_width="wrap_content"
And add this,
android:minEms="..."
Or
android:minWidth="..."
Related
I have a TextView and I set text which I receive from Backend.
the text is either from 1 to 3 words.
Maximum the textview can be 2 lines.
I am using setAutoSizeTextTypeUniformWithConfiguration
and text.breakStrategy = LineBreaker.BREAK_STRATEGY_SIMPLE
And I don't have any success.
wondering is it possible if the text is single word I don't want to split it. I would like to have it in single line with small textSize. if the text is 2 words and long I am fine to show it in 2 lines. The problem is it always breaks the word in 2 lines if it is long while I don't want.
The only solution that comes to my mind is before setting the text to a textview, check whether text has spaces in it.
If it has not that that means it's a single word, so set ptogrammatically maxlines to 1, otherwise set maxlines to 2.
EDIT: I missed text size part. I use this library for autoresizing and it worked so far https://github.com/jivimberg/AutoResizeTextView
it's automatically handled in androidx.appcompat.widget.AppCompatEditText and just set android:maxLines="2"
remove all other properties you set
I have an app in which the main view is a PopupWindow with a couple of ImageViews and an EditText on top of them. My problem is when I enter a very long text and the text box expands down and pushing the image views out of the view and I can't see them, and in order to see them back I need to delete some text.
What is the proper way of overcoming this?
thanks.
try to add into the XML something like that:
android:maxLines = "5"
android:scrollbars = "vertical"
Perhaps enclosing your LinearLayout of the PopupWindow in a ScrollView could help. LinearLayout does not allow for scrolling, if you are using it.
EDIT: In regards to the other answers, these will also work, but if you are intending to allow the user to enter as much text as they want, it may not be the best solution
See This question for more details
This should limit the height of the EditText, so even if the user types a long book in there, the field will keep its height limited to one line.
android:maxLines="1"
To limit the text to just one line, you can use this instead:
android:singleLine="true"
I'm very new to android and I want to reduce the size of EditText field in my layout.
For example if the user only need to enter 3 digits to the text field, then the size of the EditText should be small enough not the one provided by default.
Is that possible to do so?
Thanks in advance.
Try like this..
android:layout_width="wrap_content"
or
android:layout_width="20dp" //size your choice
In your Layout file set the attribute to that text field width as
android:layout_width="wrap_content"..This will take width as the text content entered into the field
You can use
android:layout_margin="size you want"
use can also use
android:layout_margin_left="size you want"
instead of "left" you can also right, top, bottom.
Is it possible to wrap a textview around a textview, where the 2nd textview would wrap to the next line under the first textview?
For example:
<This is one textview> <This is
another textview>
I have tried using android:layout_weight="1" and relative layouts, however, they dont produce this effect.
No. If you're looking to format the two bits of text differently, consider using spans within one TextView.
This will be helpful to you. You can get same effect with HTML in text view
How to display HTML in TextView?
This is impossible because the "another textview" would have a non-rectangular widget area then.
I have a textview with fixed height. I want to set a long text, but text comes at the last line getting cut by half, I want to avoid it and want to show a continuation symbol. I am giving an image here, I wan to achieve it like in the image.
Use the ellipsize attribute of TextView. By setting :
<TextView
....
android:ellipsize="end">
</TextView>
if the text is longer than your TextView you will have dots(...) at the end of the TextView.
Two line of string only possible to do like this. set ellipsize = end in text view properties.
you should use \n and special symbols from google code.