我想像Google Play电影那样对TextView
实施淡化边缘行为:
如您所见,第三行的最后一个字母具有渐弱的边缘效果。
是否有办法针对通过android:maxLines
定义的特定行实现这一目标? (例如android:maxLines="3"
)
我尝试了以下操作,但它仅与属性android:singleLine
一起使用,这不是我的目标:
<TextView
...
android:requiresFadingEdge="horizontal"
android:fadingEdgeLength="30dp"
android:ellipsize="none"
android:singleLine="true" />
在此处设置android:maxLines
不会导致完全消失。
编辑/附加:
以前,我还像here那样扩展了Shader
的同时尝试了LinearGradient
和TextView
的{{1}},但是所描述的解决方案应用了背景/前景(而且还有其他一些问题……)。
我想将Gradient
应用于maxLine行的最后3-4个字符。可以吗?
答案 0 :(得分:0)
尝试一下。.希望它能解决
public class ShadowSpan : Android.Text.Style.CharacterStyle
{
public float Dx;
public float Dy;
public float Radius;
public Android.Graphics.Color Color;
public ShadowSpan(float radius, float dx, float dy, Android.Graphics.Color color)
{
Radius = radius; Dx = dx; Dy = dy; Color = color;
}
public override void UpdateDrawState (TextPaint tp)
{
tp.SetShadowLayer(Radius, Dx, Dy, Color);
}
}