Android:Listview行背景颜色在滚动上更改

时间:2015-10-10 07:03:23

标签: android

这是我的代码

    public View getDropDownView(int position, View view, ViewGroup parent) {

        ViewHolder holder = null;  

        if(view==null)
        {
            view= inflater.inflate(R.layout.citylist, parent, false);       
            holder=new ViewHolder();
            holder.txtTitle = (TextView) view.findViewById(R.id.tv);    
            holder.txtTitle.setTextSize(TypedValue.COMPLEX_UNIT_DIP,db.getSettings().getInt(15)-3);
            holder.txtTitle.setPadding(10, 10, 10, 10);                     
            view.setTag(holder);        
        }
        else{       
            holder=(ViewHolder)view.getTag();       
        }

        holder.txtTitle.setText(data.get(position));
        if(position % 2 == 0)view.setBackgroundColor(Color.rgb(224, 224, 235));
        return view;
   }

当我在偶数行上滚动颜色时也出现在奇数行帮助

1 个答案:

答案 0 :(得分:1)

更改

if(position % 2 == 0)view.setBackgroundColor(Color.rgb(224, 224, 235));

view.setBackgroundColor(position & 1 == 0 ? Color.rgb(224, 224, 235) : android.R.color.transparent);