如何添加渐变效果的TextView的背景颜色在ListView? [英] How can I add gradient effect to background color of TextView in a ListView?

查看:138
本文介绍了如何添加渐变效果的TextView的背景颜色在ListView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在参考这些问题:

<一个href="http://stackoverflow.com/questions/14361772/adding-gradient-effect-to-textview-in-a-listview-generates-npe">Adding在ListView渐变效果的TextView产生NPE

如何改变颜色和字体上的ListView

我想知道如何去与渐变效果设置的TextView 的背景在的ListView

I would like to know how to go about setting the background of a TextView in a ListView with gradient effect?

在的问题之一以上,我最后不得不加入到的TextView 文本中的渐变效果。并通过第二个问题飞掠之后,看来我只能添加固定的背景颜色。

In one of the questions above, I ended up having the gradient effect added to the text in the TextView. And after skimming through the second question, it seems I can add only fixed background colors.

我该如何去有关添加渐变背景是什么?我应该做一个 CustomListAdapter

How do I go about adding gradient to background? Should I make a CustomListAdapter?

推荐答案

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

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

这篇关于如何添加渐变效果的TextView的背景颜色在ListView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆