question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Performance issue while using BlurView in RecyclerView items

See original GitHub issue

Please include:

  1. 1.6.6
  2. Pixel 2 API 30
  3. Lagging occurs when using blurview in recyclerview. Every recyclerview item has a blurview. I setup blurview in onBindViewHolder method.
  4. Xml and blurview setup
// CustomRecyclerViewAdapter.kt

override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
blurView.setupWith(rootBlurView)
          .setBlurAlgorithm(renderScriptBlur)
          .setBlurRadius(4f)
          .setHasFixedTransformationMatrix(false)
}

// item_recyclerview.xml

<FrameLayout
            android:id="@+id/rootBlurView"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_marginHorizontal="16dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent">

            <eightbitlab.com.blurview.BlurView
              android:id="@+id/blurView"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              app:blurOverlayColor="#78ffffff"/>

          </FrameLayout>
  1. Stacktrace in case of a crash There isn’t any crash only occurs lagging and slow performance while scrolling recyclerview. What is the correct way setup BlurView ? Where can i setup BlurView ?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Dimeziscommented, Mar 26, 2021

I can suggest you to make list item much simpler, right now it has plenty of redundant Views that serve no purpose. Something like that, just add elevation and rounded corners drawable to the ConstraintLayout.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/blurViewRoot"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="8dp"
    app:elevation="@dimen/item_photo_card_view_elevation">

    <ImageView
        android:id="@+id/ivBackground"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:scaleType="centerCrop"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintDimensionRatio="H,10:5"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/img_item_background" />

    <eightbitlab.com.blurview.BlurView
        android:id="@+id/blurView"
        android:layout_width="0dp"
        android:layout_height="@dimen/item_photo_blur_view_height"
        android:layout_gravity="bottom"
        android:layout_marginHorizontal="@dimen/item_photo_blur_view_margin_horizontal"
        android:layout_marginBottom="@dimen/item_photo_blur_view_margin_bottom"
        android:background="@drawable/bg_blur_item_photo"
        app:blurOverlayColor="@color/blur_overlay"
        app:layout_constraintBottom_toBottomOf="@id/ivBackground"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">

        <TextView
            android:id="@+id/tvTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:textAppearance="@style/TextAppearance.AppCompat.Headline"
            android:textColor="@color/white"
            tools:text="Title" />

    </eightbitlab.com.blurview.BlurView>

</androidx.constraintlayout.widget.ConstraintLayout>

Items will inflate faster and also BlurView will have much less work to do. Generally, try to keep your View hierarchy simple and set the root of the BlurView as close as possible.

This will not completely fix your problem, because as I said, having multiple BlurViews like this is a performance hit no matter what.

You can also try to create a custom LinearLayoutManager and override calculateExtraLayoutSpace to sort of preload off-screen Views of the list because during fast scrolling RecyclerView can create additional ViewHolders, which is a heavy operation with a BlurView. This trick, in theory, can pre-create enough ViewHolders on start when scrolling is not yet started.

But your best bet would be not to use it in the list

0reactions
yusufonderdcommented, Mar 30, 2021

Unfortunately, when i’m trying to real project, it is not working as expected. Because i have to use Coordinator layout and cardview in my view holder. I can’t fix the problem yet but i will write below this issue if there is an improvent.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bountysource
Performance issue while using BlurView in RecyclerView items.
Read more >
Recycler View Blur and Repeat Issue - Stack Overflow
Update-1 i tried using setHasSizeFixed(true) because the adapter data wont change the size of my views all are 90dp height. Not Solved the ......
Read more >
Slow rendering - Android Developers
RecyclerView or ListView: layout / draw taking too long. For issues with draw and layout, see the sections on Layout and Rendering Performance....
Read more >
How can I increase the performance of WebViews ... - Reddit
It looks like you're showing a video in each recyclerview item. I would advise you to do it differently: try to parse the...
Read more >
Must Have Libraries | CodePath Android Cliffnotes
ChipsLayoutManager - RecyclerView's LayoutManager which moves item to the next line when no space left on the current. Can represent google material chips ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found