2013-01-17 92 views
0

我能够使用自定义适配器设置一个listview显示正确的输出。现在我想改变每个listview项目的背景到一个渐变..它是如何做到的?更改ListView项目背景渐变

我的文件...

activity_main.xml中....主要XML文件

MainActivity.java ....主要活动

Item.java ....项目选择方法

ItemAdaptor ....定制适配器

list_item.xml .....项(TextView的)造型

我已经创建了我的梯度代码是一样..

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
<gradient 
android:startColor="#FFFAFAFA" 
android:centerColor="#FFFFFFFF" 
    android:endColor="#FFFAFAFA" 
    android:angle="90"/> 
</shape> 

还我怎么能更改分隔符的颜色,整个列表视图的背景颜色..

+0

在list_item.xml中放置android:background =“@ drawable/yourgraidentfilename” – Riskhan

回答

1

你有没有提到android:background="@drawable/customshape"你的rowLayout.xml,以便它知道哪个形状将被使用?也可以在你的listview标签中使用android:divider="#FFCC00"来更改分隔符颜色。将<solid android:color="#F0F0F0" />添加到您的形状以便更改背景颜色。

+0

如何命名我使用的形状android:background =“@ drawable/rectange”是否正确? rowLayout.xml中的textView标签内部 – user1910290

+0

我得到了drawable和列表背景之间的差距请参阅photo http://s14.postimage.org/5jeuvb4fl/Capture.png如何消除 – user1910290

1

对此tutorial

作者创建的列表视图与渐变效果一看,我觉得这是你所需要的东西。