• 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);
    //                }
    //            }
    //        }
    如果你无法简洁的表达你的想法,那只说明你还不够了解它。
  • 相关阅读:
    SQL GUID和自增列做主键的优缺点
    php 一维数组去重
    php + crontab 执行定时任务
    PHP内置函数生成随机数的方法汇总
    PHP替换回车换行的三种方法
    Yii2查询之where条件拼装
    yii2 使用阿里大鱼短信
    javascript对数据处理
    Vue 404页面处理
    vue 中view层中方法的使用
  • 原文地址:https://www.cnblogs.com/zhuochangjing/p/5169461.html
Copyright © 2020-2023  润新知