当前位置:网站首页>About the flicker problem caused by using universalimageloader to load pictures and refresh data in recyclerview
About the flicker problem caused by using universalimageloader to load pictures and refresh data in recyclerview
2022-07-24 13:56:00 【Senzhiqianshou】
About the RecyclerView Use in UniversalImageLoader Flicker problem caused by loading picture refresh data
Let's start with an effect picture :
This is what I'm using RecyclerView With the help of ItemTouchHelper A drag and drop effect with the help of . I call after successfully dragging notifyDatasetChanged When updating the data, the picture flashes .
Then I began to find solutions online . In the end, it didn't achieve the expected effect , But it is not to say that online methods are not good , Here it is , I'd like to summarize the following points :
1. If it's not used UIL Frame loading picture , It's the original imageView.setImage Load in the way of and call notifyDatasetChanged perhaps notifyItemRangeChanged(start,end) A flash occurs when the entire data is refreshed , It can be attributed to RecyclerView Own factors .
terms of settlement :
(1) Try to give each item Set up separate id, That is to say adapter Zhongyao setHasStableIds(true), And then in getItemId Return your item Of id. Google first recommends users to use this method , Set up id It will be solved later position Dislocation and many other inexplicable problems .
(2) close RecyclerView Default Item Animation effect .
((DefaultItemAnimator)recyclerView.getAnimator()).setSupportsChangeAnimations(false);The above methods can well solve the flicker problem caused by their own factors .
2. use UIL The flicker produced by the frame .
First of all, this should be UIL Problems caused by your own loading mechanism .UIL There can be multi-level cache loading . Directly bind Viewholder In time Display Display of methods , Will be in holder When reusing, the process of multi-level loading is constantly called , Class I will talk about the transition from memory cache to disk cache . I haven't studied the whole loading process in detail , But there is no doubt that , And ordinary imageView.setImage Compared with the way , It's a lot more complicated . In fact, when I close the memory cache to load , Found that when refreshing data ,UIL The first thing to show is your default image in the configuration item , Then the real picture is displayed , Although the time is relatively short , But the transition moment is still relatively clear . Then I turned on the memory cache , Then I don't see the default picture , But blink . ad locum , I can venture to speculate that :
(1) The loading speed of memory cache is much faster than that of disk cache
(2) Blinking is actually a transition from the default image to the real image , It's just , The loading speed of memory cache is much faster than that of disk cache , As a result, the default pictures are directly displayed before they are finished , But after all, it is a transition , There is still a time difference , So there is a flicker .
So , To test my guess , The following method is specially written :
/** * redefinition UIL How to display pictures <br> * UIL There can be multiple levels of caching ,( Memory cache , Disk caching ). * Directly through display Method display picture , In general operation, it is completely OK Of . But if it comes to RecyclerView Full update of data , * Such as {@link RecyclerView.Adapter#notifyDataSetChanged()} perhaps {@link android.support.v7.widget.RecyclerView.Adapter#notifyItemChanged(int)} * And so on , It will flash . Online statements are very complicated , Some say it is RecyclerView Self contained item Animation effects and so on . Results the investigation found * yes UIL Caused by the mechanism of loading pictures by itself . This method can solve the problem of flicker . * @param view * @param imgUrl * @param option */
public void showImage(ImageView view, String imgUrl, DisplayImageOptions option){
// Make sure that the memory cache is configured in the current load configuration true
Bitmap bmp= ImageLoader.getInstance().getMemoryCache().get(imgUrl);
if(bmp!=null){
view.setImageBitmap(bmp);
}else{
// Make sure that the disk cache is configured in the current loading configuration true
File cache=ImageLoader.getInstance().getDiskCache().get(imgUrl);
if(cache!=null){
// Here, according to specific needs , You can define yourself Bitmap Compressed item of , However, there is generally no need to customize it again
//UIL The initial configuration of determines the compression result , The effect is better , direct decode That's it
view.setImageBitmap(BitmapFactory.decodeFile(cache.getAbsolutePath()));
}else{
// If the first two items are not , Prove that the image has not been cached , Honestly load it in the traditional way
ImageLoader.getInstance().displayImage(imgUrl,view, option);
}
}
} Now? , Let's see the effect : 
perfect , No more flickering .
边栏推荐
- Flink综合案例(九)
- R语言使用epiDisplay包的statStack函数基于因子变量通过分层的方式查看连续变量的统计量(均值、中位数等)以及对应的假设检验、对连续数据进行对数化之后符合参数检验条件自动执行参数检验
- 网络安全——使用Exchange SSRF 漏洞结合NTLM中继进行渗透测试
- SQL Server 启停作业脚本
- Afnetworking data raw request mode
- 网络安全——文件上传白名单绕过
- XSS white list
- Network security - penetration using evil maid physical access security vulnerabilities
- Nmap安全测试工具使用教程
- Browser failed to get cookies, browser solution
猜你喜欢

【无标题】rhcsa第一次作业

在EXCEL表格中如何进行快速换行

Sringboot plugin framework implements pluggable plug-in services

Network security - file upload whitelist bypass

2021-07-09

Paper notes: swing UNET: UNET like pure transformer for medicalimage segmentation

Nessus security testing tool tutorial

Network security - filtering bypass injection

Network security - war backdoor deployment

CSDN垃圾的没有底线!
随机推荐
NOIP2021 T2 数列
Network security - file upload penetration test
JS get object attribute value
Unity行人随机行走不碰撞
Data formatting widget
JS execution mechanism
Detailed explanation of switch link aggregation [Huawei ENSP]
如何在Ubuntu 18.04和Debian 9上安装PHP 5.6
Flink高级特性和新特性(八)
Why are there "two abstract methods" in the functional interface comparator?
网络安全——文件上传内容检查绕过
CSDN垃圾的没有底线!
【无标题】rhcsa第一次作业
Network security - file upload whitelist bypass
字符串——剑指 Offer 58 - II. 左旋转字符串
Lazy loading of pictures
Flex layout
关于不定方程解的个数的问题
SQL subquery
Network security - war backdoor deployment