如何使TextView具有渐弱的边缘?

E. *_*uku 9 android textview android-recyclerview

我有一些一般的编程知识,但我是android开发的新手,我已经开始使用RecyclerView,我也使用cardview过.但在某些情况下,标题太长了,我只想添加一个渐弱的边缘.

我在这里搜索过,但找不到任何东西.所以我自己尝试了,但是我无法让它发挥作用.我也在外面使用它RecyclerView,但结果仍然相同.

我正在使用的代码.

<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"/>
Run Code Online (Sandbox Code Playgroud)

我想在Play Store的这张图片中制作淡出的TextView:

图片

任何帮助,将不胜感激.提前致谢...

gus*_*s27 21

根据https://developer.android.com/reference/android/R.attr.html#fadingEdge android:fadingEdge已弃用.

它应该与:requiresFadingEdge="horizontal"android:ellipsize="none":

android:requiresFadingEdge="horizontal"
android:fadingEdgeLength="40dp"
android:ellipsize="none"
Run Code Online (Sandbox Code Playgroud)

我建议使用类似的东西,android:layout_width="match_parent"或者android:layout_width="100dp"如果你喜欢文字褪色.

  • 它仍然对我不起作用。如果我使用android:requiresFadingEdge =“ horizo​​ntal”,它什么也不会给我,但是如果我将它与android:singleLine =“ True”一起使用,那么它在textView的末尾会给我三个点(...) (2认同)
  • @ gus42这不起作用,我正在试用OnePLus Device OS 6.0.1版.任何建议!! (2认同)