Saturday, June 23, 2018

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

Leave a Comment

My client requested a collapsing view (triggered by a recycler view) that doesn't graphically belong to AppBar / Toolbar abstraction. 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.

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. All examples show collapsing views only inside AppBars!

So - is it or is it not possible to collapse any view anywhere with events from some 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. It works as required, but looks hacky...

enter image description here

2 Answers

Answers 1

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).

But you have to keep AppBarLayout to get things worked. (Don't forget to set app:elevation="0dp" to the AppBarLayout)


Is it or is it not possible to collapse any view anywhere with events from some RecyclerView?

Yes, it is possible. By attaching an OnScrollListener to the RecyclerView and manually collapsing it. But I think the AppBarLayout method will be enough for this.

Answers 2

If I have understood the question correctly, this may help you. Expandable Layout

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment