2015-05-28 8 views
7

Ho visto tempi di caricamento molto lunghi per le immagini nella nostra app utilizzando Glide 3.6 + a RecyclerView utilizzando GridLayoutManager. Le immagini sono tutte intorno a 20kb-40kb. Sembra che la planata acceleri tutte le richieste che fanno sì che le immagini impieghino un po 'di tempo per caricarsi una volta che inizi a scorrere più in basso nell'elenco. Ho allegato i log dalla classe GenericRequest.Glide fa la coda di ogni richiesta di immagine? I carichi di Recyclerview sono molto lenti durante lo scorrimento

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 

Si chiedeva se qualcuno potesse fornire alcune informazioni su quale potrebbe essere il problema. Forse è il tempo necessario per ridimensionare la vista? Sto usando match_parent per la larghezza della vista e un'altezza fissa di circa 200dp.

Le immagini vengono caricate utilizzando

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" 
     /> 

EDIT: Come da @VladimirMironov commento. Ho aggiornato con il pool aumentato e cancellando i carichi in sospeso quando una vista viene riciclata. Questo sembra aver aiutato un po 'quando si scorre velocemente. Fornire un override o non utilizzare "match_parent" per la vista fornisce vantaggi quando si tratta di visualizzare le misurazioni? Ci sono ancora casi in cui una vista non verrà mostrata per quasi 5 secondi.

+3

Ci sono due cose che si può provare a migliorare le prestazioni: 1. Annullare la richiesta di download in 'RecyclerView.Adapter.onViewRecycled' (tramite chiamata' Glide.clear') 2. Aumentare la dimensione del pool di 'ViewHolder' tramite' recycler.getRecycledViewPool(). SetMaxRecycledViews (0, 2 * numColumns) ' –

+0

@VladimirMironov interessante non sapendo di questi mi darò un colpo –

+0

@VladimirMironov ho modificato il mio pubblicare con alcune informazioni aggiuntive –

risposta

0

Passare a PercentFrameLayout ha notevolmente aiutato il mio progetto con la velocità di scorrimento delle immagini in RecyclerView. (adapted from Bumptech's "Issues" section of their GitHub page)

<android.support.percent.PercentFrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="@dimen/product_image_height" (208dp) 
    android:layout_gravity="top" 
    android:background="@color/placeholder_bg" 
    <ImageView 
     android:id="@+id/product_image" 
     app:layout_widthPercent="100%" 
    /> 
</android.support.percent.PercentFrameLayout> 

Poi nel onBindViewHolder()

int srcHeight = getImageHeight();  // hopefully you know the image height & width 
int srcWidth = getImageWidth(); 

PercentFrameLayout.LayoutParams layoutParams = 
     (PercentFrameLayout.LayoutParams) viewHolder.productImage.getLayoutParams(); 
PercentLayoutHelper.PercentLayoutInfo layoutInfo = layoutParams.getPercentLayoutInfo(); 

if(srcHeight > 0) {  // being careful about potential divide by 0 errors 
    layoutInfo.aspectRatio = (float)srcWidth/(float)srcHeight; 
} else { 
    layoutInfo.aspectRatio = 1; 
} 

layoutParams.height = 0; 
viewHolder.productImage.setLayoutParams(layoutParams); 

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

Infine, è necessario aggiungere il pacchetto di supporto per PercentFrameLayout alle tue dipendenze in build.gradle(Module:app)

compile 'com.android.support:percent:23.1.1' 
Problemi correlati