You are applying to your TextView a compound Drawable on the right.. to make the three dots appear in this scenario, you have to apply a android:drawablePadding="{something}dp" attribute to the TextView as well. Hope it helps!
text_view. post(new Runnable() { @Override public void run() { if (text_view. getLineCount() < text_view. getMaxLines()) { // do stuff } } });
You can use android:ellipsize="start" or android:ellipsize="middle" according your need.
you can extend the TextView class and overwrite the setText() function. In this function you check for text length or word cound. Better than counting the text length or the word cound a better way would be to use the "maxLines" attribute along with "ellipsize" attribute to attain the desired effect.
This is a common problem. Try using the following:
android:scrollHorizontally="true"
android:ellipsize="end"
android:maxLines="1"
.............. the scrollHorizontally is the "special sauce" that makes it work.
This will also make a single line with ellipsise
android:singleLine="true"
Use this
android:ellipsize="end"
android:singleLine="true"
Don't use this without fully aware of what output comes
android:ellipsize="end"
android:maxLines="1"
When you use maxlines = 1
it will some time truncate most of the characters.
The way it worked for me on multiple devices / APIs was programmatically like this (where tv is your TextView):
if (tv.getLineCount() > 1) {
int lineEndIndex = tv.getLayout().getLineEnd(0);
String text = tv.getText().subSequence(0, lineEndIndex - 3) + "\u2026";
tv.setText(text);
}
So all the answers above cater to the requirement that only 1 line and then the ellipsis should appear. However if you want the ellipsis to appear after certain lines of text, then you should use the following:
android:ellipsize="end"
android:maxLines="2"
android:singleLine="false"
With this the ellipsis will appear only after 2 lines. Note: Its important to have singleLine as false.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With