在本机中具有交替颜色的ListView [英] Listview with alternating color in react native
本文介绍了在本机中具有交替颜色的ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有对象数组,如下例所示;
I have array of objects like the example below;
[{
"id" : 13100,
"key" : "Emlak Vergisi",
"y" : 135638.98
}, {
"id" : 13154,
"key" : "Çevre Temizlik ",
"y" : 956.17
}, {
"id" : 19998,
"key" : "Genel Tahakkuk",
"y" : 89030.62
}, {
"id" : 24998,
"key" : "Gecekondu ve So",
"y" : 42721.07
}, {
"id" : 60000,
"key" : "Ortak Gelirler",
"y" : 827.42
}
]
是否可以使每个项目具有交替颜色的列表视图?
Is it possible to have a listview with alternating color for each item?
推荐答案
我会说这种方法更干净:
I would say this approach is cleaner:
renderRow(rowData, sectionID, rowID) {
let style = [
styles.row,
{'backgroundColor': colors[rowID % colors.length]}
];
return (<View style={style}/>);
}
let colors = ['#123456', '#654321', '#fdecba', '#abcdef'];
let styles = StyleSheet.create({
row: {
// .. rows style
}
});
这样,您可以轻松地为列表中的每一行添加特殊颜色(不仅按偶/奇类型)
This way you can easily add a specail color to each row in the list (not only by even/odd type)
这篇关于在本机中具有交替颜色的ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文