您的位置:首页 > 其它

listview隔行变色

2016-02-15 09:53 218 查看
这个实现起来应该非常简单,但是我用的时候效果就是出不来,后来发现是因为listview的item本身设置背景色后,在代码中设置的隔行变色效果不出现。这里mark一下

[code]   @Override
    public View renderView(int pos, Vacation auditInfo, View view) {
         ButterKnife.bind(this,view);
//        TextView applicant= (TextView) view.findViewById(R.id.text_name);
        MyListener myListener = new MyListener(pos);
        applicant.setText(auditInfo.getApplicantName());
        //下面这四行实现变色
        if(pos%2==1)
            view.setBackgroundColor(Color.WHITE); //颜色设置
        else
            view.setBackgroundColor(Color.BLUE);//颜色设置

        return view;
    }


或者

[code]    private int[] colors=new int[]{0x30FF0000,0x300000FF};//这里没有引用进去使用,只是简单引用数组运算

  @Override
    public View renderView(int pos, Vacation vacationInfo, View view) {
        ButterKnife.bind(this, view);
        MyListener myListener = new MyListener(pos);
        time.setText(vacationInfo.getVacationDate().toString());

        //变色
        int colorPos=pos%colors.length;
        if(colorPos==1)
            view.setBackgroundColor(Color.argb(42, 200, 200, 100)); //颜色设置
        else
            view.setBackgroundColor(Color.argb(42, 100, 100, 100));//颜色设置

        return view;


所以切记在item当中不要设置背景色了

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: