zoukankan      html  css  js  c++  java
  • android设置listview的item颜色相间排列

    //        viewHolder复用了item,持有的position是会随着listView的滑动变化的
    //        if ((viewHolder.getPosition() + 1) % 2 == 0) {
    //            int color = Color.argb(255, 101, 181, 109);
    //            viewHolder.getConvertView().setBackgroundColor(color);
    //        } else {
    //            int color = Color.argb(255, 255, 255, 255);
    //            viewHolder.getConvertView().setBackgroundColor(color);
    //        }
    
            /*
            * position参数是不会随着listView的滑动而变化的,即使viewHolder复用的item发生了变化,
            * 设置颜色的那个item的position是不会变的,所以可以这么来设置item的颜色相间排列
            * */
    //        if (position % 2 == 0) {
    //            int color = Color.argb(255, 255, 255, 255);
    //            viewHolder.getConvertView().setBackgroundColor(color);
    //        } else {
    //            int color = Color.argb(255, 101, 181, 109);
    //            viewHolder.getConvertView().setBackgroundColor(color);
    //        }
    
    //        这里不用循环也可以的,因为getView方法本身就会去循环listView来画item,这里的
    //        循环i和position是等价的,i的 值就是position的值
    //        for (int i = 0; i < getCount(); i++) {
    //            if (position == i) {
    //                if (i % 2 == 0){
    //                    int color = Color.argb(255, 255, 255, 255);
    //                    viewHolder.getConvertView().setBackgroundColor(color);
    //                } else {
    //                    int color = Color.argb(255, 101, 181, 109);
    //                    viewHolder.getConvertView().setBackgroundColor(color);
    //                }
    //            }
    //        }
    如果你无法简洁的表达你的想法,那只说明你还不够了解它。
  • 相关阅读:
    开机自动挂载分区
    Wine安装
    ubuntu 将idea/vscode快捷方式加入到启动器中
    在Linux上安装Java
    httpclient
    shiro
    redis-随笔
    maven
    spring的aop
    spring事务知识梳理
  • 原文地址:https://www.cnblogs.com/zhuochangjing/p/5169461.html
Copyright © 2011-2022 走看看