I got a linear layout that I want to move up when a Snackbar appears.
I saw many examples how to do this with FloatingButton, but what about a regular view?
I got a linear layout that I want to move up when a Snackbar appears.
I saw many examples how to do this with FloatingButton, but what about a regular view?
I'm going to elaborate on the approved answer because I think there's a slightly simpler implementation than that article provides.
I wasn't able to find a built-in behavior that handles a generic moving of views, but this one is a good general purpose option (from http://alisonhuang-blog.logdown.com/posts/290009-design-support-library-coordinator-layout-and-behavior linked in another comment):
then, in your layout file add a layout_behavior as below:
where the layout_behavior is the full path to your custom behavior. There's no need to subclass LinearLayout unless you have a specific need to have a default behavior, which seems uncommon.
NO need of Co-ordinator layout using a regular view align the snack bar to the bottom of the view, and place the button on top of it, on click of button of whatever your logic is show snackbar or linear layout.
You need to add a behaviour to your LinearLayout and embed it in a CoordinatorLayout. You might want to read this: http://alisonhuang-blog.logdown.com/posts/290009-design-support-library-coordinator-layout-and-behavior
I implemented this and found when the snackbar disappeared the view remained up with white space in the snackbars place, apparently this is known if animations have been disable on the device.
To fix this I changed the onDependentViewChanged method to store the initial Y position of the view this behaviour is attached to. Then on removal of the snackbar reset the position of that view to the stored Y position
In addition to Travis Castillo's answer: To allow triggering consecutive SnackBars, within
onDependentViewChanged()
, you have to cancel any possibly ongoing animation started byonDependentViewRemoved()
:Without cancelling, the LinearLayout will jump down below the 2nd SnackBar when a SnackBar is replaced by another SnackBar.
I've written a library which additional views can be added to animate with the SnackProgressBar. It also includes progressBar and other stuff. Try it out https://github.com/tingyik90/snackprogressbar
Suppose you have the following views to animate.
Create an instance of SnackProgressBarManager in your activity and includes the view to animate.
When a SnackProgressBar is shown or dismissed, these views will be animated accordingly.