简体   繁体   English

是否可以在AppBar / CollapsingToolbarLayout之外设置折叠布局?

[英]Is it possible to set Collapsing layouts outside of AppBar / CollapsingToolbarLayout?

My client requested a collapsing view (triggered by a recycler view) that doesn't graphically belong to AppBar / Toolbar abstraction. 我的客户端请求了一个折叠视图(由回收器视图触发),该视图不是图形上属于AppBar / Toolbar抽象。 While I was able to fake it somehow with the mentioned view sitting really inside CollapsingToolbarLayout, I really feel the code is clumsy and will be a nightmare to maintain. 虽然我能够以某种方式伪造它,并且所提到的视图确实位于CollapsingToolbarLayout内部,但我真的觉得代码很笨拙并且将成为维护的噩梦。

The name CoordinatorLayout suggests that maybe the collapsing / parallax behaviour could be used anywhere in view hierarchy, but I couldn't find neither example nor any proof of in Android docs. CoordinatorLayout这个名字表明可能在视图层次结构中的任何地方都可以使用折叠/视差行为,但我在Android文档中找不到任何示例或任何证据。 All examples show collapsing views only inside AppBars! 所有示例都只显示AppBars中的折叠视图!

So - is it or is it not possible to collapse any view anywhere with events from some RecyclerView? 那么 - 是否或者不可能使用来自某些RecyclerView的事件在任何地方折叠任何视图?

Since it was requested - a schematic view of the layout. 因为它被要求 - 布局的示意图。 But the question is really more general. 但问题实际上更为笼统。 As stated above - I've implemented it putting the collapsable square inside AppBar and setting background to white. 如上所述 - 我已经实现了将可折叠方块放在AppBar中并将背景设置为白色。 It works as required, but looks hacky... 它按要求工作,但看起来很hacky ......

在此输入图像描述

I really feel the code is clumsy and will be a nightmare to maintain. 我真的觉得代码很笨拙,并且会成为维护的噩梦。

I don't think so. 我不这么认为。

Also CollapsingToolbarLayout is optional (Remember, you can use minHeight if you want). 此外, CollapsingToolbarLayout是可选的(请记住,如果需要,可以使用minHeight )。

But you have to keep AppBarLayout to get things worked. 但你必须保持AppBarLayout才能使事情AppBarLayout进行。 (Don't forget to set app:elevation="0dp" to the AppBarLayout ) (别忘了将app:elevation="0dp"设置为AppBarLayout


Is it or is it not possible to collapse any view anywhere with events from some RecyclerView ? 是否或者不可能使用来自某些RecyclerView事件在任何地方折叠任何视图?

Yes, it is possible. 对的,这是可能的。 By attaching an OnScrollListener to the RecyclerView and manually collapsing it. 通过将OnScrollListener附加到RecyclerView并手动折叠它。 But I think the AppBarLayout method will be enough for this. 但我认为AppBarLayout方法就足够了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM