Android 将第一行和最后一行设置为自定义可绘图

Android 将第一行和最后一行设置为自定义可绘图,android,listview,custom-adapter,Android,Listview,Custom Adapter,我正在尝试使listview的最后一行和第一行具有圆形边缘。现在我只是想让第一行有圆角。我可以做到这一点,但一些随机的行,通常是5-7和15或16行,也会被设置为圆角背景,我不知道为什么 以下是我尝试将圆角设置为可绘制的部分: public View getView(int position, View convertView, ViewGroup parent) { View vi = convertView; if (convertView == null) {

我正在尝试使listview的最后一行和第一行具有圆形边缘。现在我只是想让第一行有圆角。我可以做到这一点,但一些随机的行,通常是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将其设置为无效。有什么想法吗?

这很可能是因为框架正在将一个非空的
convertView
传递到您的
getView
方法中,该方法恰好来自您的第一行

最简单的修复方法是取消设置除第一行之外的每一行的后台资源:

   if (position == 0){
       holder.rellay.setBackgroundResource(R.drawable.roundededges);
   } else {
       holder.rellay.setBackgroundResource(0);
   }

你需要什么来确定尺寸。我的意思是在@Override public int getCount()中{//TODO自动生成的方法存根}