如何制作带有渐隐边缘的 TextView? [英] How to make TextView with fading edge?

查看:64
本文介绍了如何制作带有渐隐边缘的 TextView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我在 android:fadingEdge 已弃用.

它应该适用于 requiresFadingEdge="horizo​​ntal"android:ellipsize="none" :

android:requiresFadingEdge="horizo​​ntal"android:fadingEdgeLength="40dp"机器人:椭圆尺寸=无"

如果您希望文本褪色,我建议您使用 android:layout_width="match_parent"android:layout_width="100dp" 之类的内容.

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:

解决方案

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.

这篇关于如何制作带有渐隐边缘的 TextView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆