Image flickering on notifyDataSetChanged()
See original GitHub issueProblems cause by this bug:
- image flickering
- if you load image grid, scroll down, then scroll up, images are reloaded again
- first batch of images consume TWICE as much memory.
It looks like there is a bug here:
/* com.nostra13.universalimageloader.core.ImageLoader:193 */
ImageSize targetSize = ImageSizeUtils.defineTargetSizeForView(imageView, configuration.maxImageWidthForMemoryCache, configuration.maxImageHeightForMemoryCache);
String memoryCacheKey = MemoryCacheUtil.generateKey(uri, targetSize);
First time when views is not created, it generates image cache key with screenWidth x screenHeight. And when views already created, it generates a new image cache key viewWidth x viewHeight.
Since keys is different both times, images are considered different so it loads the same image twice into memory.
So if we have a grid with 20 images, we will get:
- cache with 40 images
- grid flickering or image reloading on scrolling
It can be very easy reproduced with samples that comes with UIL:
- call notifyDataSetChanged one more time. or
- just scroll down then up.
If someone want a quick fix, replace cache key generator with static uri:
/* com.nostra13.universalimageloader.core.ImageLoader:194 */
String memoryCacheKey = uri; // MemoryCacheUtil.generateKey(uri, targetSize);
Issue Analytics
- State:
- Created 10 years ago
- Comments:36 (8 by maintainers)
Top Results From Across the Web
How to Avoid That RecyclerView's Views are Blinking when ...
However, when we refreshed the RecyclerView by notifyDataSetChanged() , it is blinking for a short time, especially strange on cell's inner image view....
Read more >android - RecyclerView blinking on notifyDataSetChanged()
ok im trying the second solution , and there is an error , it says " notifyItemRangeInserted(int, int)' in 'androidx.recyclerview.
Read more >Image flickering on notifyDataSetChanged() - Bountysource
Problems cause by this bug: 1. image flickering 2. if you load image grid, scroll down, then scroll up, images are reloaded again...
Read more >How to fix blinking issue for RecyclerView notify changes
And you may noticed that whenever you use adapter. NotifyDataSetChanged(), adapter.notifyItemChanged(int position) etc methods then your ...
Read more >Android – RecyclerView blinking after notifyDatasetChanged()
setHasStableIds(true) and override getItemId(int position) . Without stable IDs, after notifyDataSetChanged() , ViewHolders usually assigned to not to same ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I solved this “bug” (it is definitely not) with a much simpler approach, - no need for custom helpers or solutions, just use View’s tag and ViewHolder pattern properly:
Yeah, it’s a lot of tags, but this will prevent your ImageViews from being reloaded upon any subtle change to a ListView/GridView state.
P.S. Take NavigationDrawer open/close event as an example of such a “subtle change” - this will be followed by
notifyDataSetChanged()
even if no change to adapter’s underlying data occured.Hello!
I fixed this problem with helper-class (clear animation of
ImageView
and settingBitmap
from memory cache manually):My loading strategy is:
ImageView
before loading (resetViewBeforeLoading(true)
);Bitmap
for item in memory cache - It will be set without fade;Bitmap
for item in memory cache - It will be downloaded and set inImageView
with fade. That’s why that code is solution for me. MyDisplayImageOptions
:I use
FadeInBitmapDisplayer
in myDisplayImageOptions
and I think thatImageLoader
don’t clearAnimation
after settingBitmap
. When you callsAdapter.notifyDataSetChanged()
,AdapterView
callsView.requestLayout()
that is invalidates his children and restartAnimation
.