android - 如何在 ImageView 上放置高亮透明文本?

标签 android xml textview transparent

我有这样的看法:

<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/

相关文章:

android - 适用于 Android 的 Flex AIR 应用程序可以作为进程运行吗?

xml - XSLT - 在输出中用转义文本替换撇号

c# - X文档,X元素 : Sequence contains no matching element

android - 自定义 ListView 项目的外观

android - 不同设备上的字体大小

android - DaggerMock 正在生成意外实例

java - HttpURLConnection 从不使用 gzip

Android XML 错误解析 XML : junk after document element

xml - 轻量级富文本 XML 格式?

android - 如何将样式应用于我拥有的所有 TextView?