问题描述
在参考这些问题:
Adding在ListView渐变效果的TextView产生NPE
和
我想知道如何去与渐变效果设置的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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!