Glide是否将每个图像请求排队?滚动时,Recyclerview的加载速度非常慢 [英] Does Glide queue up every image request? Recyclerview loads are very slow when scrolling

查看:69
本文介绍了Glide是否将每个图像请求排队?滚动时,Recyclerview的加载速度非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用Glide 3.6 +使用GridLayoutManager的RecyclerView的应用程序中,图像的加载时间非常长.图像都在20kb-40kb左右.滑行似乎使所有请求排队,一旦开始向下滚动列表,图像就会花相当长的时间才能加载.我已经附加了GenericRequest类的日志.

I have been seeing very long load times for images in our app using Glide 3.6 + a RecyclerView using a GridLayoutManager. The images are all around 20kb-40kb. It seems that glide queues up all the requests which causes the images to take quite awhile to load once you start scrolling further down the list. I've attached the logs from the GenericRequest class.

V/GenericRequest﹕ finished setup for calling load in 0.170291 this: 249721749
V/GenericRequest﹕ finished onSizeReady in 0.36724999999999997 this: 249721749
V/GenericRequest﹕ finished run method in 0.763083 this: 249721749
V/GenericRequest﹕ Got onSizeReady in 0.041249999999999995 this: 991315424
V/GenericRequest﹕ finished setup for calling load in 0.15479199999999999 this: 991315424
V/GenericRequest﹕ finished onSizeReady in 0.30008399999999996 this: 991315424
V/GenericRequest﹕ finished run method in 0.499959 this: 991315424
V/GenericRequest﹕ Got onSizeReady in 0.060584 this: 1029510845
V/GenericRequest﹕ finished setup for calling load in 0.200625 this: 1029510845
V/GenericRequest﹕ finished onSizeReady in 0.39233399999999996 this: 1029510845
V/GenericRequest﹕ finished run method in 0.670084 this: 1029510845
V/GenericRequest﹕ Got onSizeReady in 0.048374999999999994 this: 516458536
V/GenericRequest﹕ finished setup for calling load in 0.188666 this: 516458536
V/GenericRequest﹕ finished onSizeReady in 0.379916 this: 516458536
V/GenericRequest﹕ finished run method in 0.654083 this: 516458536
V/GenericRequest﹕ Resource ready in 1012.49325 size: 2.18359375 fromCache: false this: 671303046
V/GenericRequest﹕ Got onSizeReady in 0.073833 this: 356666200
V/GenericRequest﹕ finished setup for calling load in 0.240667 this: 356666200
V/GenericRequest﹕ finished onSizeReady in 0.460792 this: 356666200
V/GenericRequest﹕ finished run method in 0.780708 this: 356666200
V/GenericRequest﹕ Got onSizeReady in 0.064583 this: 347417463
V/GenericRequest﹕ finished setup for calling load in 0.242583 this: 347417463
V/GenericRequest﹕ finished onSizeReady in 0.45758299999999996 this: 347417463
V/GenericRequest﹕ finished run method in 0.7521249999999999 this: 347417463
V/GenericRequest﹕ Got onSizeReady in 0.142833 this: 671303046
V/GenericRequest﹕ finished setup for calling load in 0.38966599999999996 this: 671303046
V/GenericRequest﹕ finished onSizeReady in 0.703708 this: 671303046
V/GenericRequest﹕ finished run method in 1.851125 this: 671303046
V/GenericRequest﹕ Got onSizeReady in 0.056957999999999995 this: 634418527
V/GenericRequest﹕ finished setup for calling load in 0.21787499999999999 this: 634418527
V/GenericRequest﹕ finished onSizeReady in 0.443083 this: 634418527
V/GenericRequest﹕ finished run method in 0.7567499999999999 this: 634418527
V/GenericRequest﹕ Resource ready in 3443.041335 size: 2.18359375 fromCache: false this: 249721749
V/GenericRequest﹕ Resource ready in 4110.604794 size: 3.8623809814453125 fromCache: false this: 1054166306
V/GenericRequest﹕ Resource ready in 3824.033544 size: 3.8623809814453125 fromCache: false this: 991315424
V/GenericRequest﹕ Resource ready in 3773.0562109999996 size: 3.8623809814453125 fromCache: false this: 1029510845
V/GenericRequest﹕ Resource ready in 4542.90796 size: 2.18359375 fromCache: false this: 516458536
V/GenericRequest﹕ Resource ready in 4171.866168 size: 3.8623809814453125 fromCache: false this: 634418527
V/GenericRequest﹕ Resource ready in 4474.170752 size: 3.8623809814453125 fromCache: false this: 356666200
V/GenericRequest﹕ Resource ready in 4496.104085 size: 2.18359375 fromCache: false this: 671303046
V/GenericRequest﹕ Resource ready in 4814.625126999999 size: 2.18359375 fromCache: false this: 347417463

想知道是否有人可以提供有关该问题可能是什么的见解.调整视图大小可能需要花费时间?我正在使用match_parent作为视图的宽度,并将固定高度设置为200dp左右.

Was wondering if anyone could provide some insight into what the issue might be. Maybe its the time it takes to resize to the view? I am using match_parent for the width of the view and a fixed height of about 200dp.

图像使用

Glide.with(fragmentContext)
          .load(imageUrl)
          .centerCrop()
          .placeholder(R.drawable.placeholder)
          .into(viewHolder.productImage);

XML

<ImageView
      android:id="@+id/product_image"
      android:layout_width="match_parent"
      android:layout_height="@dimen/product_image_height" (208dp)
      android:layout_gravity="top"
      android:background="@color/placeholder_bg"
      />

根据@VladimirMironov注释.我已经更新了增加的池,并在回收视图时清除了待处理的负载.快速滚动时,这似乎有所帮助.在进行视图测量时,是否为视图提供覆盖或不使用"match_parent"会带来任何好处?在某些情况下,视图在近5秒钟内不会显示.

As per @VladimirMironov comment. I've updated with the increased pool and clearing the pending loads when a view is recycled. This seems to have helped a bit when scrolling fast. Does providing an override or not using "match_parent" for the view provide any benefits when in comes to view measuring? There are still cases where a view wont show for almost 5 secs.

推荐答案

添加以下几行,您会看到改进的地方

recyclerView.setHasFixedSize(true);
yourAdapter.setHasStableIds(true);//recycler adapter

覆盖onViewRecycled()&清除以前的Glide请求

Glide.with(imageHolder.preview.getContext()).clear(imageHolder.preview);

这篇关于Glide是否将每个图像请求排队?滚动时,Recyclerview的加载速度非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆