How to make TextView with fading edge?

僤鯓⒐⒋嵵緔 提交于 2019-12-18 00:50:51

问题


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:


回答1:


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.




回答2:


android 6.0.1

This code works

android:ellipsize="marquee"
android:marqueeRepeatLimit="0"
android:singleLine="true"

and don't forget

textView.setSelected(true);



回答3:


In my case, @Эвансгелист Evansgelist's answer worked perfectly, although the fading was a little too subtle (for that particular project).

In the end, I had to add android:singleLine="true" to @gus27's answer to make it work and get the effect I wanted:

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


来源:https://stackoverflow.com/questions/37631112/how-to-make-textview-with-fading-edge

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!