折叠时折叠的工具栏模糊图像 [英] Collapsing toolbar blur image when collapsed

查看:97
本文介绍了折叠时折叠的工具栏模糊图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工具栏需要一些帮助.

i need some help with my toolbar.

现在,当我向上滚动时,我使用的折叠工具栏的图像均已折叠. 我知道我可以使用contentScrim使工具栏透明,因此将图像视为工具栏背景".

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?

推荐答案

您可以使用此库. ( RealTimeBlurView )
对于模糊效果,只需将imageview放在blurview后面. 要实现所需的功能,只需在滚动应用栏时更改blurview的alpha.

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));
    }
});

更新

FastBlur
这是另一个基准测试项目,用于展示android中所有可能的模糊方法.演示中的算法,并在您的项目中使用它.

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.

希望这会有所帮助!

这篇关于折叠时折叠的工具栏模糊图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆