块滚动以及“展开/折叠可折叠工具栏" [英] Block scroll along with Expand/Collapse Collapsible Toolbar

本文介绍了块滚动以及“展开/折叠可折叠工具栏"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用了Collapsible Toolbar.在活动启动时,可折叠工具栏处于展开状态,并且启用了滚动功能,并且可以正常工作.但是现在我需要显示全屏错误布局,以防我的API失败.在那种情况下,我必须折叠工具栏以阻止滚动效果.

I was using Collapsible Toolbar in my app. On activity launch Collapsible Toolbar is expanded state with scrolling enabled and its working well normally. But now I have a requirement to show a full screen error layout in case my API fails. In that case I have to collapsed toolbar with scrolling effect blocked.

错误布局显示重试"按钮.重试时,我再次调用API,如果API成功,则必须再次展开工具栏并启用滚动效果.

Error Layout shows a Retry Button. On Retry I make API call again and if API gives success I have to again expand Toolbar and enable scrolling effect.

我可以使用setExpanded(标志,动画)折叠工具栏,但在这种情况下,当显示错误布局时,我无法阻止可折叠工具栏的滚动效果.

I was able to collapse toolbar with setExpanded(flag, animate) but in that case I am not able to block scrolling effect of Collapsible Toolbar while error layout is shown.

我需要提供一种阻止和取消阻止滚动效果的方法+展开/折叠工具栏.任何帮助将非常感激.. !!!

I need to provide a way to block as well as unblock scroll effect + Expand/Collapse Toolbar. Any help would be really appreciated.. !!!

推荐答案

我创建了一个库 AppBarrr 根据我之前的回答将屏幕锁定在扩展模式.

I created a library AppBarrr to lock the screen in expanded mode, based on my previous answer.

正如我所说的,Toolbar的高度是关键:CollapsingToolbarLayout会折叠直到Toolbar的高度,然后扩展到AppBarLayout的高度.

As I said, the height of the Toolbar is the key: the CollapsingToolbarLayout will collapse until the Toolbar's height and will expand until the AppBarLayout's height.

使用此库,您必须将两个布局设置为Toolbar和扩展布局(用于锁定屏幕和滚动),它将创建一个CollapsingToolbarLayout并在内部填充这些布局.

With this library, you must set two layouts as the Toolbar and your Expanded Layout (used to lock the screen and the scroll), it will create a CollapsingToolbarLayout and inflate these layouts inside.

您可以声明动画的持续时间,内部CollapsingToolbarLayout的颜色,折叠/展开的标题的样式,甚至是锁定布局的高度...如果在外部单击,也可以隐藏展开的布局.它可以在扩展布局内支持NestedScrollViewScrollView. 文档和示例应用程序可在Github上找到.

You can declare the animations duration, the color of the inner CollapsingToolbarLayout, the collapsed/expanded title's style, even the height of the locked layout... You could also hide the Expanded Layout if you click outside it. It can support NestedScrollView and ScrollView inside the Expanded Layout. The documentation and a sample app are available on Github.

对于那些不想使用该库的人,我以前的答案显示了这样做的方法.这是上一个答案的输出:

For those who don't want to use the library, my previous answer shows the way to do it. Here's the output of the previous answer:

基本上,这是相同的概念,但是不需要编写完整的类,而对于lib,您只需要在xml中有一个简单的小部件就可以了!

Basically, this is the same concept, but no need to write a full class, with the lib you just need to have a simple widget in xml and that's it!

随意使用,叉子或测试.希望它会有用;)

Feel free to use, fork or test. Hope it will be useful ;)

这篇关于块滚动以及“展开/折叠可折叠工具栏"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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