简体   繁体   中英

Android ListView with radius top bottom

Dose anyone know how to make the radius can always show on top when I scrolling the ListView?

在此输入图像描述

在此输入图像描述

在此输入图像描述

I am using BaseAdapter to implement the first & last item background.

Here is the adapter code,

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if(this.dataset != null && !this.dataset.isEmpty() && this.dataset.size() > 0){
        if(convertView == null){
            convertView = inflater.inflate(R.layout.corner_list_item_layout, null);
        }

        ViewHolder holder = (ViewHolder) convertView.getTag();
        if(holder == null){
            holder = new ViewHolder();  
            holder.item = (RelativeLayout) convertView.findViewById(R.id.corner_list_item_relativelayout);
            holder.label = (TextView) convertView.findViewById(R.id.corner_list_item_label);
            convertView.setTag(holder);
        }           

        if (position == 0) {
            if (position == (this.getCount() - 1)) {
                holder.item.setBackgroundResource(R.drawable.app_list_corner_round_light);
            } else {
                holder.item.setBackgroundResource(R.drawable.app_list_corner_round_top_dark);
            }
        } else if (position == (this.getCount() - 1)) {
            if(position % 2 == 0){
                holder.item.setBackgroundResource(R.drawable.app_list_corner_round_bottom_dark);
            }else{
                holder.item.setBackgroundResource(R.drawable.app_list_corner_round_bottom_light);
            }

        } else {
            if(position % 2 == 0){
                holder.item.setBackgroundResource(R.drawable.app_list_corner_middle_dark);
            }else{
                holder.item.setBackgroundResource(R.drawable.app_list_corner_middle_light);
            }
        }

        String str = String.valueOf(this.dataset.get(position));        
        holder.label.setText(str);

    }
    return convertView;
}`
  1. Place the ListView inside any layout.
  2. Prepare a 9-patch border image and place this as a background to the Layout.

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM