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?
In addition to Travis Castillo's answer:
To allow triggering consecutive SnackBars, within onDependentViewChanged()
, you have to cancel any possibly ongoing animation started by onDependentViewRemoved()
:
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
float translationY = Math.min(0, ViewCompat.getTranslationY(dependency) - dependency.getHeight());
ViewCompat.animate(child).cancel(); //cancel potential animation started in onDependentViewRemoved()
ViewCompat.setTranslationY(child, translationY);
return true;
}
Without cancelling, the LinearLayout will jump down below the 2nd SnackBar when a SnackBar is replaced by another SnackBar.