Slim Recent: fix scroll lag when Auto Expand and improve RecyclerView performances
3 steps: ------- https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html#setHasFixedSize(boolean) setHasFixedSize void setHasFixedSize (boolean hasFixedSize) RecyclerView can perform several optimizations if it can know in advance that RecyclerView's size is not affected by the adapter contents. RecyclerView can still change its size based on other factors (e.g. its parent's size) but this size calculation cannot depend on the size of its children or contents of its adapter (except the number of items in the adapter). If your use of RecyclerView falls into this category, set this to true. It will allow RecyclerView to avoid invalidating the whole layout when its adapter contents change. Parameters hasFixedSize boolean: true if adapter changes cannot affect the size of the RecyclerView. --------- make the scroll smooth after you open the panel and scroll it the first time https://developer.android.com/reference/android/support/v7/widget/LinearLayoutManager.html#getExtraLayoutSpace(android.support.v7.widget.RecyclerView.State) getExtraLayoutSpace int getExtraLayoutSpace (RecyclerView.State state) Returns the amount of extra space that should be laid out by LayoutManager. By default, LinearLayoutManager lays out 1 extra page of items while smooth scrolling and 0 otherwise. You can override this method to implement your custom layout pre-cache logic. Note:Laying out invisible elements generally comes with significant performance cost. It's typically only desirable in places like smooth scrolling to an unknown location, where 1) the extra content helps LinearLayoutManager know in advance when its target is approaching, so it can decelerate early and smoothly and 2) while motion is continuous. Extending the extra layout space is especially expensive if done while the user may change scrolling direction. Changing direction will cause the extra layout space to swap to the opposite side of the viewport, incurring many rebinds/recycles, unless the cache is large enough to handle it. Parameters state RecyclerView.State Returns int The extra space that should be laid out (in pixels). ------- Async background job: do it at higher priority and remove the set orig priority code, Android should restore default priority after doInBackground returns. Change-Id: I002590f98e50a3cd516ce8ba2241f5e3fc36aeeb Signed-off-by:Josue Rivera <prbassplayer@gmail.com>
Loading
Please sign in to comment