我正在使用 ListView,其中的交替行是彩色的。但是当 ListView 超过屏幕的长度时,在滚动时,替代颜色会消失。 下面是我的代码:
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = getActivity().getLayoutInflater()
.inflate(R.layout.problem_list_row, null);
if(position%2!=0) {
convertView.setBackgroundColor(Color.parseColor("#ebebeb"));
}
}
if(position%2!=0){
convertView.setBackgroundColor(Color.parseColor("#ebebeb"));
}
/* some code */
return convertView;
}
下面附上 ListView 的图像。
最佳答案
试试这段代码
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = getActivity().getLayoutInflater()
.inflate(R.layout.problem_list_row, null);
}
if(position%2==0)
{
// SET EVEN POSITION COLOR
convertView.setBackgroundColor(Color.parseColor("#ebebeb"));
}
else
{
//SET ODD POSITION COLOR
}
/* some code */
return convertView;
}
希望对你有帮助
关于java - ListView 的替代颜色在 Android 中滚动屏幕时消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27677096/