gpt4 book ai didi

android - 如何在网格中设置备用单元格颜色

转载 作者:太空狗 更新时间:2023-10-29 16:23:18 25 4
gpt4 key购买 nike

如何在网格中设置备用单元格颜色?我发现了很多问题/教程关于如何设置行颜色但没有关于细胞的颜色。提前致谢

最佳答案

如果您有很多关于 listView 的示例,为什么不直接使用 getView 方法,因为 getView 方法用于适配器,而适配器用于 View 、列表和网格。只需根据view在adapterview中的位置设置view的背景即可。

protected void getView(AdapterView<> adapterView, View convertView, int position, long id)
{

LayoutInflater inflater = (LayoutInflater)context.getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
View view =inflater.inflate(yourlayout.xml, null);

if(position%2==0)
view.setBackgroundColor(color1);
else
view.setBackgroundColor(color2);
return view;
}

关于android - 如何在网格中设置备用单元格颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9062512/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com