使用AQuery快速滚动时,ImageView在ListView中在错误的位置可见

时间:2015-02-25 09:35:45

标签: android android-listview

我在listView的适配器中获得了以下getView:

    @Override
public View getView(int position, View convertView, ViewGroup viewGroup) {
    View view = convertView;
    if (view == null) {
        view = LayoutInflater.from(context).inflate(R.layout.item_message, null);
    }

    final Message msg = getItem(position);
    final AQuery aq = new AQuery(view);

    aq.id(R.id.message_baloon).background(myMessage ? R.drawable.chat_message_own : R.drawable.chat_message_other);

    // shared image
    if (msg.getPhotos() != null && msg.getPhotos().size() != 0) {
        aq.id(R.id.sent_photo).visible();
        aq.image(msg.getPhotos().get(0).getUrl(), true, true, 540, R.drawable.room_details_gallery_placeholder);
        aq.clicked(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //show fullsecreen photo
            }
        });

    } else {
        aq.id(R.id.sent_photo).gone();            
    }

    if (msg.getText() == null || msg.getText().length() == 0) {
        aq.id(R.id.message).gone();
    } else {
        aq.id(R.id.message).text(msg.getText());
        aq.id(R.id.message).visible();
    }

    return view;
}

该方法实际上更长,但此部分包含与该ImageView相关的所有内容。因此,正如标题所述,当滚动速度非常快时,使用" R.id.sent_photo"的ImageView对于没有照片而不是一秒钟的位置是可见的,它仍然可见(我正在使用的那个AndroidQuery库)。

谢谢!

3 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,我在自定义适配器中使用了以下方法,我得到了解决方案。

在ListViewItemsAdapter中添加以下方法:

@Override
    public int getCount() {
        return alUpgradeTour.size();
    }

    @Override
    public int getItemViewType(int position) {
        return position;
    }

    @Override
    public int getViewTypeCount() {

        return getCount();
    }

尝试一下,你也会得到解决方案。

答案 1 :(得分:0)

试试这个,似乎AndroidQuery库在下载之前没有放置占位符图像

    if (msg.getPhotos() != null && msg.getPhotos().size() != 0) {
        aq.id(R.id.sent_photo).visible();
        aq.id(R.id.sent_photo).setImageResource(R.drawable.room_details_gallery_placeholder);
        aq.image(msg.getPhotos().get(0).getUrl(), true, true, 540, R.drawable.room_details_gallery_placeholder);
        aq.clicked(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //show fullsecreen photo
            }
        });

    } else {
        aq.id(R.id.sent_photo).gone();
    }

答案 2 :(得分:0)

解决方案不使用内存缓存:    aq.image(msg.getPhotos()。get(0).getUrl(), false ,true,540,R.drawable.room_details_gallery_placeholder);

AndroidQuery在该图像功能的某处执行以下操作

public static void async(Activity act, Context context, ImageView iv, String url, boolean memCache, boolean fileCache, int targetWidth, int fallbackId, Bitmap preset, int animation, float ratio, float anchor, Object progress, AccountHandle ah, int policy, int round, HttpHost proxy, String networkUrl){

    Bitmap bm = null;

    if(memCache){
        bm = memGet(url, targetWidth, round);
    }

    if(bm != null){
        iv.setTag(AQuery.TAG_URL, url);     
        Common.showProgress(progress, url, false);
        setBmAnimate(iv, bm, preset, fallbackId, animation, ratio, anchor, AjaxStatus.MEMORY);
    }else{
        Bit...

因此,如果它从memCache获得位图,则调用setBmAnimate

private static void setBmAnimate(ImageView iv, Bitmap bm, Bitmap preset, int fallback, int animation, float ratio, float anchor, int source){
    bm = filter(iv, bm, fallback);...

过滤器是:

    private static Bitmap filter(View iv, Bitmap bm, int fallback){
    //ignore 1x1 pixels
    if(bm != null && bm.getWidth() == 1 && bm.getHeight() == 1 && bm != empty){        
        bm = null;
    }

    if(bm != null){
        iv.setVisibility(View.VISIBLE);
    }else if(fallback == AQuery.GONE){
        iv.setVisibility(View.GONE);
    }else if(fallback == AQuery.INVISIBLE){
        iv.setVisibility(View.INVISIBLE);
    }

    return bm;