E. Quku E. Quku - 6 months ago 206
Android Question

How to make TextView with fading edge?

I have some general programming knowledge, but I am new to android developing, and I have started with

RecyclerView
and I have used
cardview
too. But in some cases the title there is too long and I just want to add a fading edge.

I have searched in here but I couldn't find anything. So I tried it myself, but I couldn't get it working. I have used it outside the
RecyclerView
too, but still the same result.

The code I am using.

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Hello World"
android:id="@+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="25sp"
android:textStyle="bold"
android:fadingEdge="horizontal" <!-- I think those 2 lines should do it,
android:fadingEdgeLength="40dp"/>


I want to make the fading TextView as in this picture from Play Store

Any help would be appreciated. Thanks in advance...

Answer

According to https://developer.android.com/reference/android/R.attr.html#fadingEdge android:fadingEdge is deprecated.

It should work with requiresFadingEdge="horizontal" and android:ellipsize="none" :

android:requiresFadingEdge="horizontal"
android:fadingEdgeLength="40dp"
android:ellipsize="none"

And I would recommend to use something like android:layout_width="match_parent" or android:layout_width="100dp" if you like the text to be faded.