Search code examples
androidlayoutbluruiblureffect

Android: Blur listview behind a layout


I have a listview and a layout that is in front of the listview. I want that layout to have as a background the blur of the listview that is in his back. Like in the image. The blur changes according to listview scrolling. How do I do this?


Solution

  • This lib is what you need https://github.com/Dimezis/BlurView

    <eightbitlab.com.blurview.BlurView
        android:id="@+id/blurView"
        android:layout_width="match_parent"
        android:layout_height="66dp"
        android:layout_alignParentBottom="true"
        >
        <!--anything below this view will be blured-->
    </eightbitlab.com.blurview.BlurView>
    

    in app.gradle defaultConfig

        renderscriptTargetApi 23
        renderscriptSupportModeEnabled true
    

    and in activity

        blurView = (BlurView) findViewById(R.id.blurView);
    
        final View decorView = getWindow().getDecorView();
        final View rootView = decorView.findViewById(android.R.id.content);
        final Drawable windowBackground = decorView.getBackground();
    
        blurView.setupWith(rootView)
                .windowBackground(windowBackground)
                .blurAlgorithm(new RenderScriptBlur(this, true)) //Preferable algorithm, needs RenderScript support mode enabled
                .blurRadius(10);