Code Monkey home page Code Monkey logo

Comments (8)

wenmingvs avatar wenmingvs commented on August 28, 2024

我在开发微博的时候,也遇到这个问题。最后确定问题是由于RecyclerView复用ViewHolder引起的,
RecyclerView内部会自动判断ViewHolder是否需要重新刷新来加载新的数据,这套判断的逻辑有时候遇到一些复杂的item布局的时候,就会出现问题,导致一些有图的微博item复用了之前无图的微博item的ViewHolder,图片也就显示不出来了

解决办法:让RecyclerView认为这个ViewHolder需要重新刷新来加载新的数据

在设置图片前,手动调用

(Viewholder).recyclerview.setVisibility(View.GONE);
(Viewholder).recyclerview.setVisibility(View.VISIBLE);

这样图片就不会出现乱序问题了

from weibo.

cyq7on avatar cyq7on commented on August 28, 2024

这两句我加上了的,然而还是会乱,好忧桑。。。

from weibo.

wenmingvs avatar wenmingvs commented on August 28, 2024

使用ImageLoader是否有使用占位图?尝试使用下列代码给ImageLoader增加如下配置:

  options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.message_image_default)
                .showImageForEmptyUri(R.drawable.message_image_default)
                .showImageOnFail(R.drawable.message_image_default)
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .considerExifParams(true)
                .build();

  ImageLoader.getInstance().displayImage(mData.get(position), holder.imageItem, options);

图片可以自己设置

from weibo.

cyq7on avatar cyq7on commented on August 28, 2024

嗯,这些当然都设置了

from weibo.

wenmingvs avatar wenmingvs commented on August 28, 2024

写下你的开源项目的地址,我帮你看一下

from weibo.

cyq7on avatar cyq7on commented on August 28, 2024

lz,我发你的源码你收到了吗

from weibo.

wenmingvs avatar wenmingvs commented on August 28, 2024

没有收到,请发到[email protected]

from weibo.

joetang1989 avatar joetang1989 commented on August 28, 2024

可参考Android-Universal-Image-Loader中机制,将ImageView的hashcode作为key,图片url作为value,存储线程安全的hashmap中。下载后display时,根据ImageView的hashcode从hasmap中取图片url,如果被复用了,那么取出来的url与图片的url不一致,不需要显示。

from weibo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.