Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

picture

like image 248
E. Quku Avatar asked Jun 04 '16 14:06

E. Quku


People also ask

What is fading edge android?

Android-FadingEdgeLayoutA versatile layout that fades its edges regardless of child view type.

How do you get 3 dots at the end of a TextView text?

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!

How do I center a TextView layout?

When you have a LinearLayout view, you can center the TextView widget by setting the layout_width and layout_height attributes of the TextView to match_parent and the gravity attribute to center . You can also center multiple TextView widgets by using the layout_weight attribute.

What is the use of TextView?

A TextView displays text to the user and optionally allows them to edit it. A TextView is a complete text editor, however the basic class is configured to not allow editing.


1 Answers

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.

like image 114
gus27 Avatar answered Sep 22 '22 08:09

gus27