【发布时间】:2018-02-14 01:20:54
【问题描述】:
我在 onResume 方法中从 recyclerView “重新创建”适配器时遇到了一些问题。 基本上,这是我的方案。
MainActivit -ViewPager
- fragment A (has a recyclerView)
- fragment B (nop)
- fragment C (nop)
- fragment D (it has the same recyclerView as the framgnet A)
onResume 我一直呼吁
> myCustomAdapter adapter = new myCustomAdapter (
> mListItems,getContext(),ParseUser.getCurrentUser().getObjectId(),
> "type");
> recyclerView.setAdapter(adapter);
但这会导致一些问题,例如当我从另一个活动返回 MainActivity 时。例如。
Activityt A
- click on item in recylerView
- start Activity B
Activity B
user does some actions, sees some news, and returns to Activity A.
Activity A
recreates the adapter and set recyclerView.setAdapter (new Adapter);
this is slow, causes a delay of 2 seconds after onBackPressed is pressed in Activity B.
我还有一个 setMenuVisibility 方法,它也与 onResume 做同样的事情,因为如片段 D 中所述,我在片段 A 中有 recyclerView,所以如果用户在 recyclerView 中进行了一些更改即在片段 D 中,当用户返回片段 A 时,我需要更新片段 A 的 recyclerView。
为什么 Fragment D 中的 recyclerView 在 Fragment A 中?
我们可以考虑以下内容,在片段 A 中,我有一个仅包含“用户兴趣”的 recyclerView,在片段 D 中,我有用户信息,例如用户名、照片等......还有“用户兴趣”。
结论:问题是当我从Activity B返回到Activity A时,当我在viewPager中在fragment A和fragment D之间交替时,这会导致重新创建适配器的延迟.
在这种情况下我该怎么办?
我为这糟糕的英语道歉,我正在使用谷歌翻译。
【问题讨论】:
-
您是否在 RecyclerView 项目中加载图像?
-
我是,而且可能方式不对。我需要在 recyclerView 的每一行中添加 8 个不同图像的 ImageView。
-
图片加载导致卡顿,请使用 Glide 或 Picasso 等图片加载库
-
我刚刚删除了添加 ImageViews 的代码,这确实“解决了”问题,但我真的需要 ImageViews。我已经用毕加索了。目前我正在添加 imageViews,如下所示。 holder.ContainerImageViews.addView (imageView);删除这段代码后,延迟就停止了,你认为如果我在xml中添加8个imageView,会不会对性能产生影响?或者同样的延迟会继续吗?每个 imageView 的大小为 45dp / 45dp
标签: android performance android-recyclerview