且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何添加渐变效果的TextView的背景颜色在ListView?

更新时间:2023-09-22 23:15:04

您只需要创建一个绘制资源(见下面的例子),并将其添加到您的列表项创建的布局。

You just need to create a drawable resource (see an example below), and add it to the layout you created for your ListItem.

提拉(在你的水库\绘制文件夹 - 将其命名为任何 - listgrad.xml为前)可能是这样的:

The drawable (in your res\drawable folder - name it whatever - listgrad.xml for ex) could look like:

<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文件)这样的code片断:

The you would add it to the layout for your list item (the layout.xml file you define for this) like this code snippet:

<TextView
        android:id="@+id/ranking_order"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/list_grad"
        />
...