I use the following RoboTextView xml declaration:
<com.package.utils.RobotoTextView
android:id="#+id/ttli_small_desc"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginRight="6dp"
android:textSize="12dp"
android:paddingBottom="6dp"
android:maxLines="5"
android:ellipsize="end"
android:textColor="#color/selectable_text_black_to_white"
bit:fontType="light"/>
It is a custom view object, but I've tested it with a standard TextView and the same problem occurs. The only thing this custom view does is allow me to use RobotoLight font. A bit outdated of a technique now but it's there so I use it.
Anyways what I'd expect is a maximum of 5 lines which should look like this
word words words
words words words
word word words
words word
words words words...
But here is what I'm getting:
Basically it ellipsizes the text, but then just picks right back up afterwards. I've played around with singleLine=false and other random attributes trying to fix it but I've struck out so far. Does anyone know how to fix this?
Thanks!
Related
I have an TextView with a big fontsize and if I have a long word only the last char is put into the next line. For example :
Zusammenarbei
t
Now I would like to format the text to look like this:
Zusammenarb -
t
Is there a possibility to achive this?
I guess better than doing Hyphenation, you can do something better.Consider the following image.
I guess green one will be much suitable for your need. Just declare your textview as follows:
<TextView
android:id="#+id/yourUniqueID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:ellipsize="end" <!--THIS WILL DO FOR YOU-->
android:maxLines="1"
android:text="test"/>
Look at the break strategy of the TextView
android:breakStrategy="high_quality"
constant value description
high_quality 1 Line breaking uses high-quality strategy, including hyphenation.
I know this question already asked multiple times but I could not able to solve my problem with available solutions.
I applied all solutions which are available on other stack overflow threads.
Requirements :
If string length is more than 140 than show only 140 characters and at last add ".." at last.
If string is less than 140 characters then no need to append ".." at last.
What I have tried:
<TextView
android:id="#+id/tvIssueBody"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLength="140"
android:paddingBottom="5dp"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="#dimen/detail_text_size"/>
I have tried above code but it is not working and I tried all other properties mixture also but It is not working.
Shall I have to do with str.subString(0,141) option? There is no way to limit 140 characters using textview property?
Thanks to all in advanced. Any help will be appreciated.
There's no way to get this to work exactly as you want with a built in TextView. First off, a TextView will not allow anyone to add more than maxLength characters. So if they try to add 200 characters, the last 60 would be dropped. This means even 141 won't work if you want to keep that data. And Elipsize doesn't ellipsize where you want it- it ellipsizes where it needs to in order to fit the text on screen. You can't force it to do so after a given length.
What you want really need is a custom view or a subclass of TextView, so you can override onDraw to draw a different string than the set text (a hand ellipsized version of it).
I'm working on a layout that includes both English and Hebrew (intended as right-to-left) text, in separate views. When a line of Hebrew text gets beyond a certain length, it becomes written left-to-right (I assume that this has to do with length because it looks fine with shorter text, and when I display it on a tablet instead of a phone).
The relevant view looks like this:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:gravity="center"
android:textDirection="rtl"
android:text="#string/tx_middle_text"
android:textSize="#dimen/big_text_dp" />
and the string is defined in strings.xml like this:
<string name="tx_middle_text">טקסט בעברית</string>
(I've replaced the original text, which was 50 characters long, and made up entirely of Hebrew letters and white-spaces).
Note the text has the rtl attribute. I've tried replacing it with anyRtl, and I've tried changing gravity to "right" - neither helps.
I need the text to remain in one line and be cut off with an ellipsis if it doesn't fit - as it is, that's what happens, but with the text written left-to-right.
How can I fix this?
Edit: For an ad-hoc solution I made a shorter string as an alternative resource for the smaller layout (it works as long as the text is less than one line long on a given device), but I'd still like to know if there's a general solution to this.
RTL is detected automatically by the system depending on the characters. i.e for Arabic characters, text will be drawn from right to left.
This is an example on how my spinner is drawn. For this TextView:
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/spinner_item"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textSize="15sp"
android:gravity="center_vertical|start"
android:textColor="#color/spinner_filter_text"
android:ellipsize="end"
android:singleLine="true"
android:paddingStart="20dp"
android:paddingEnd="20dp"/>
And these strings:
<string name="all_categories">All Categories</string> (values)
(values-ar)
The result is:
If I modify the TextView with:
android:layout_width="100dp"
The result is:
Which I think is fine... Note that in strings.xml the string direction for ar language is wrong but Android is drawing it properly. I guess it is because of some Android Studio setting.
Replace android:singleLine="true" with
android:lines="1"
android:maxLines="1"
also add android:ellipsize="end"
I have something like a message system and listview that hold the messages.So I want to show let's say only the first 10 symbols of the message and after ellipsis.I couldn't find information how to do it, so if somebody can help me.
I assume you know how to set up an adapter.
You can achieve that by editing your XML layout file. You limit the max amount of text your TextView can hold, and tell it to add ellipsis if it's longer.
<TextView
android:id="#+id/secondLineTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:maxLength="10"
android:ellipsize="end"/>
Example from here
Android ellipsize doesn't work as expected in some cases.
What I'm expecting is three dots on the last line, but in cases it adds the 3 lines plus a few characters related to the rest of the text afterward. Is it possible to change this behavior?
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:singleLine="false"
android:ellipsize="end"
android:maxLines="2"
android:layout_marginBottom="16dp"/>
According to me android:ellipsize="end" depends on the words in the TextView.
If following word is lengthy then it omits the word and shows ...
If the following word is small then it will fit correctly and last fill ...
Hope it helps.