我有一个由自定义适配器驱动的ListView,它可以根据行的内容动态更改每行的背景色。getView如下所示:
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View row = convertView;
Power power = powers.get(position);
if(row == null)
{
row = getLayoutInflater().inflate(android.R.layout.simple_list_item_2, parent, false);
}
TextView text1 = (TextView)row.findViewById(android.R.id.text1);
TextView text2 = (TextView)row.findViewById(android.R.id.text2);
text1.setText(power.name);
text2.setText(power.getAttackLine());
row.setBackgroundColor(0xFF0000FF);
return row;
}除了当我从列表中选择一个项目时,标准的red/orange高亮显示只显示在行的后面,并且只在它的每一边的几个像素上可见之外,所有的效果都很好。有没有办法让所选内容显示在背景之上?
发布于 2009-12-03 20:17:36
在布局中的<ListView>元素中尝试使用android:drawSelectorOnTop="true"。
发布于 2009-12-03 23:17:56
我认为问题在于您使用的是simple_list_item_2,它内置了一些填充/边距。我建议您制作自己版本的simple_list_item_2,其中的高度和宽度都设置为fill_parent。你可以看到最新的simple_list_item_2 here。
https://stackoverflow.com/questions/1838820
复制相似问题