我正在努力做到这一点,以便我的列表视图的最后一行和第一行将具有圆角边缘。现在我只是想让第一行有圆角。我能够做到这一点,但一些随机行通常是 5-7 和 15 或 16 行也将设置为圆角背景,我不知道为什么。
这是我的适配器代码的一部分,我尝试将圆角设置为可绘制:
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
if (convertView == null) {
vi = inflater.inflate(R.layout.row, null);
holder = new ViewHolder();
holder.title = (TextView) vi.findViewById(R.id.title);
holder.desc = (TextView) vi.findViewById(R.id.details);
holder.date = (TextView) vi.findViewById(R.id.date);
holder.price = (TextView) vi.findViewById(R.id.price);
holder.location = (TextView) vi.findViewById(R.id.location);
holder.newImage = (ImageView) vi.findViewById(R.id.savedNewItemsRibbon);
holder.rellay = (RelativeLayout) vi.findViewById(R.id.widget30);
//holder.image = (ImageView) vi.findViewById(R.id.thumb);
vi.setTag(holder);
}else{
holder = (ViewHolder) vi.getTag();
}
if(position == 0 && firstRow){
holder.rellay.setBackgroundResource(R.drawable.roundededges);
firstRow = false;
}else{
//vi.setBackgroundColor(Color.WHITE);
}
Log.d("MySQL", "COunt:"+position);
holder.price.setText(data.get(position).getPrice());
holder.location.setText(data.get(position).getUrl());
datasource = new PostDataSource(activity);
datasource.open();
if(datasource.checkIfNew(data.get(position).getTitle())){
holder.newImage.setVisibility(View.VISIBLE);
//vi.setBackgroundColor(Color.YELLOW);
}else{
holder.title.setTextColor(Color.BLACK);
}
holder.title.setText(data.get(position).getTitle());
holder.desc.setText(data.get(position).getDescription());
holder.date.setText(data.get(position).getPubDate());
holder.location.setText(data.get(position).getCity());
//holder.title.setText(data.get(0).getTitle());
//imageLoader.DisplayImage((data.get(position).getThumbnail()), activity,holder.image, 72, 72);
URL url = null;
try {
url = new URL((data.get(position).getThumbnail()));
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
InputStream content = null;
/*
try {
//content = (InputStream)url.getContent();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Drawable d = Drawable.createFromStream(content , "src");
Bitmap mIcon1 = null;
try {
mIcon1 =
BitmapFactory.decodeStream(url.openConnection().getInputStream());
} catch (IOException e) {
e.printStackTrace();
}
holder.image.setImageBitmap(Bitmap.createScaledBitmap(mIcon1, 72, 72, false));
*/
positionCount++;
return vi;
}
我试过只使用 position==0 将其设置为无济于事。有任何想法吗?