Collapsing toolbar blur image when collapsed

本小妞迷上赌 提交于 2019-12-13 08:18:16

问题


i need some help with my toolbar.

Right now i use a collapsing toolbar with image wich collapsed when i scroll up. I know i can use contentScrim to make the Toolbar transparent and therefore see the image as "toolbar background".

However, i want the image to blur(/fade) when the toolbar is collapsed.

Any suggestions how to achieve this?


回答1:


You can use this library. (RealTimeBlurView)
For the blur effect, just put the imageview behind the blurview. To achieve what you want just change blurview's alpha when the app bar is scrolled.

appbar.addOnOffsetChangedListener(new OnOffsetChangedListener() {
    @Override
    public void onOffsetChanged(final AppBarLayout appBarLayout, final int verticalOffset) {
        float offsetAlpha = (appBarLayout.getY() / appbar.getTotalScrollRange());
        blurView.setAlpha( 1 - (offsetAlpha * -1));
    }
});

UPDATE

FastBlur
Here's another benchmarking project to showcase all the possible blurring methods in android.
Just get the fastest algorithm from the demo and use it in your project.

Hope this helps!



来源:https://stackoverflow.com/questions/44979733/collapsing-toolbar-blur-image-when-collapsed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!