如何在maxLine TextView的最后一行应用水平淡化边缘

问题描述 投票:0回答:1

我想像Google Play Movie一样对TextView实施淡化边缘行为:

enter image description here

如您所见,第三行的最后一个字母具有淡化边缘效果。有没有办法实现这个通过android:maxLines定义的特定线? (例如android:maxLines="3"

我尝试了以下但它只使用属性android:singleLine,这不是我的目标:

<TextView
    ...
    android:requiresFadingEdge="horizontal"
    android:fadingEdgeLength="30dp"
    android:ellipsize="none"
    android:singleLine="true" />

在这里设置android:maxLines反而不会导致任何褪色。

编辑/附加条件:

以前我也尝试过ShaderLinearGradient,同时像TextView那样扩展here,但是所描述的解决方案应用了背景/前景(并且还有一些其他问题......)。

我想将Gradient应用于maxLine行的最后3-4个字符。这有可能吗?

android textview fade fadeout truncate
1个回答
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);
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.