gpt4 book ai didi

android - 如何使 TextView 具有渐变边缘?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:21:23 24 4
gpt4 key购买 nike

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

我在 here 中搜索过但我找不到任何东西。所以我自己试了一下,但我无法让它工作。我也在 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"/>

我想使 TextView 像 Play 商店的这张图片一样淡入淡出:

picture

最佳答案

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

它应该与 requiresFadingEdge="horizo​​ntal"android:ellipsize="none" 一起工作:

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

如果您希望文本淡出,我建议使用类似 android:layout_width="match_parent"android:layout_width="100dp" 的东西。

关于android - 如何使 TextView 具有渐变边缘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37631112/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com