我有这样的看法:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="3dp" >
<ImageView
android:id="@+id/imageView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignBottom="@+id/description" />
<TextView
android:id="@+id/description"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#80000000"
android:gravity="right"
android:padding="10dp"
android:textColor="#fff"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
/>
</RelativeLayout>
我需要使透明 TextView 像阴影一样,这意味着,我想让它从底部变暗,从顶部变亮,从底部变暗到顶部变亮, 但我的代码在整个 TextView 中都是相同的颜色 但我需要让它像阴影一样,从底部变暗到顶部变浅,我的颜色是单调 #80000000 我想让它高亮,像阴影
我该怎么做?
最佳答案
XML:
您只需创建一个可绘制资源(参见下面的示例),并将其添加到您为 ListItem 创建的布局中。
drawable(在你的 res\drawable 文件夹中 - 随便命名 - listgrad.xml for ex)看起来像:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="@color/gradient_start"
android:endColor="@color/gradient_end"
android:angle="-270" />
</shape>
您可以将它添加到列表项的布局(您为此定义的 layout.xml 文件),如以下代码 fragment :
<TextView
android:id="@+id/ranking_order"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/list_grad"
/>
...
Java:
TextView secondTextView = new TextView(this);
Shader textShader=new LinearGradient(0, 0, 0, 20,
new int[]{Color.GREEN,Color.BLUE},
new float[]{0, 1}, TileMode.CLAMP);
secondTextView.getPaint().setShader(textShader);
关于android - 如何在 ImageView 上放置高亮透明文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29557994/