小编gsw*_*ski的帖子

RecyclerView与GridLayoutManager和Picasso显示错误的图像

更新#1

添加了hasStableIds(true)并将Picasso更新到版本2.5.2.它没有解决问题.

再生产:

RecyclerView with GridLayoutManager(spanCount = 3).列表项是带有ImageView的CardViews.

当所有项目都不适合时,在一个项目上调用notifyItemChanged的屏幕会导致对onBindViewHolder()的多次调用.一个调用是来自notifyItemChanged其他人的位置,用于屏幕上不可见的项目.

问题:

有时,传递给notifyItemChanged的位置的项目加载了属于不在屏幕上的项目的图像(很可能是由于视图持有者的回收 - 尽管我会假设如果项目保留在原位,那么传递的视图持有者会是一样的).

我发现Jake在这里关于调用load()的其他问题的评论,即使文件/ uri为null.图像加载到每个onBindViewHolder上.

简单示例应用:

git clone https://github.com/gswierczynski/recycler-view-grid-layout-with-picasso.git
Run Code Online (Sandbox Code Playgroud)

点击一个项目调用notifyItemChanged,其参数等于该项目的位置.

码:

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment())
                    .commit();
        }
    }

    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main, container, false);

            RecyclerView rv = (RecyclerView) rootView.findViewById(R.id.rv);

            rv.setLayoutManager(new …
Run Code Online (Sandbox Code Playgroud)

android picasso gridlayoutmanager android-recyclerview

12
推荐指数
1
解决办法
4654
查看次数