ListView滚动UI故障

时间:2016-04-07 15:16:59

标签: android listview picasso

我有一个listView,在滚动时有一个奇怪的视觉故障:

during scroll

滚动后

after scroll

这种情况间歇性地发生,除了关闭我的应用程序并开始滚动列表之外,我没有很好的方法来重现这一点。关于发生了什么的任何想法?

这是我用于此listView的arrayAdapter中的一些(可能)相关代码:

public function postQuestion(Requests\ModelRequest $request) { //your logic }

用于获取图像的毕加索代码:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // If we weren't given a view, inflate one
    ViewHolder holder;
    if (convertView == null) {
        convertView = ((Activity) context).getLayoutInflater().inflate(R.layout.event,
                parent, false);
        holder = new ViewHolder();
        holder.name = (TextView) convertView.findViewById(R.id.eventName);
        holder.date = (TextView) convertView.findViewById(R.id.eventDate);
        holder.attending = (TextView) convertView.findViewById(R.id.eventAttending);
        holder.bgImg = (ImageView) convertView.findViewById(R.id.eventsImg);
        holder.gpsIcon = (ImageView) convertView.findViewById(R.id.iconGPS);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    // Configure the view for this event
    final Event event = getItem(position);
    holder.gpsIcon.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Util.openMap(getContext(), event.getAddress());
        }
    });
    holder.name.setText(event.getName());
    holder.date.setText(Util.convertDashesToDate(event.getDate()));
    holder.attending.setText(event.getAttending());
    RequestUtil.getImageFullUrl(getContext(), event.getImage_url(), holder.bgImg, 10, 0);

    return convertView;
}

@Override
public Event getItem(int position) {
    return new Event(events.get(position));
}

static class ViewHolder {
    TextView name;
    TextView date;
    TextView attending;
    ImageView bgImg;
    ImageView gpsIcon;
}

1 个答案:

答案 0 :(得分:0)

我猜你的代码设置了图片:

 RequestUtil.getImageFullUrl(getContext(), event.getImage_url(), holder.bgImg, 10, 0);

正在UI线程上加载(下载)图像,导致阻塞线程。

我不知道您的RequestUtil背后是什么,但我建议使用Android的几个优秀图像加载库之一,例如Picasso。例如,毕加索将为您处理在后台线程上加载图像。