Android高斯模糊效果

2019-08-14  本文已影响0人  SuperTypeMen

参考:https://android.ctolib.com/github-BlurView.html
效果:

Screenshot_2019-08-14-16-57-03_看图王.png
Screenshot_2019-08-14-16-52-39.png

1、添加依赖:

implementation 'com.eightbitlab:blurview:1.6.2'

2、添加控件:

<eightbitlab.com.blurview.BlurView
            android:id="@+id/blurView"
            android:layout_alignParentBottom="true"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:blurOverlayColor="#BB141726">

        <!--Any child View here, TabLayout for example-->
       
    </eightbitlab.com.blurview.BlurView>

3、设置:
在activity的oncreate方法中加入

    val decorView = window.decorView
    val rootView = decorView.findViewById<View>(android.R.id.content) as ViewGroup
    blurView.setupWith(rootView)
        .setFrameClearDrawable(decorView.background)
        .setBlurAlgorithm(RenderScriptBlur(this))
        .setBlurRadius(20f)//0<r<25  数值越大越模糊
        .setHasFixedTransformationMatrix(true)
上一篇下一篇

猜你喜欢

热点阅读