简体   繁体   English

更改 gridview 中的项目行颜色?

[英]Change item Row color in gridview ?

hellow evreybody please can you help me to change the color of row in gridview in getView(),for example i try to change the backround by row forexample if position ==4 the 4 row will be in black .你好 evreybody 请你能帮我在 getView() 中更改 gridview 中行的颜色,例如,我尝试逐行更改背景,例如,如果位置 ==4,则第 4 行将为黑色。 but when i scrool all row changed background.但是当我滚动所有行时都改变了背景。

Your model classes of your gridItems for your adapter should have an attribute 'color' .您的适配器的 gridItems 模型类应具有属性 'color' 。

In your getView method - when the 'position' is 3,7,11...etc change the gridview layout color and use the setColor attribute of your item to set the color to that particular item.在您的 getView 方法中 - 当“位置”为 3,7,11...等时,更改 gridview 布局颜色并使用您的项目的 setColor 属性将颜色设置为该特定项目。

Along with this at the start of your getView method you can check if item.getColor is set then change the gridview layout color else it should have the default color.在 getView 方法开始时,您可以检查 item.getColor 是否设置,然后更改 gridview 布局颜色,否则它应该具有默认颜色。

For getting the desired position you can use the formula if position = (4n-1) which will give you your desired color changing positions ie 3,7,11....为了获得所需的位置,您可以使用公式 if position = (4n-1) 这将为您提供所需的颜色变化位置,即 3,7,11....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM