iamverysmart
iamverysmart

Reputation: 51

How to truncate text with a fade effect in Android?

I am aware that this question has been asked before but the accepted answer does not work, and none of the comments are helping me. How to replace ellipses with fade / fading edge in textview in Android sdk?

I am trying to use ellipsize="marquee" in order to truncate my text at the end and have a fade effect rather than an ellipsis.

<TextView
  android:layout_width="200dp"
  android:layout_height="wrap_content"
  android:text="LOREM IPSUM SCARAMOUCHE SCRARAMOUCHE GALILEO PACCIORETTY"
  android:singleLine="true"
  android:ellipsize="marquee"/>

I wish I could post a screenshot but SE wont't let me. here is what it looks like on screen

LOREM IPSUM SCARAMOUC..

the word is not fading out, and it is not displaying an ellipsis either. instead it displays 2 dots.

note that I do not want the text to scroll, I just want it to truncate with a fade effect rather than an ellipsis.

Upvotes: 4

Views: 1892

Answers (2)

gareoke
gareoke

Reputation: 746

You may also do this programmatically:

TextView yourTextView = findViewById(R.id.your_textview);    
yourTextView.setSingleLine(true);
yourTextView.setEllipsize();
yourTextView.setHorizontalFadingEdgeEnabled(true);
yourTextView.setFadingEdgeLength(20);
yourTextView.setHorizontalFadingEdgeEnabled(true);

Upvotes: 0

VendettaDroid
VendettaDroid

Reputation: 3111

You can use

android:requiresFadingEdge="horizontal"
android:fadingEdgeLength="@dimen/align_twenty"
android:fadeScrollbars="false"
android:ellipsize="none"

Upvotes: 1

Related Questions