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 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
private static float initialPositionY;
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
initialPositionY = child.getY();
float translationY = Math.min(0, dependency.getTranslationY() - dependency.getHeight());
child.setTranslationY(translationY);
return true;
}
@Override
public void onDependentViewRemoved(CoordinatorLayout parent, View child, View dependency) {
super.onDependentViewRemoved(parent, child, dependency);
child.setTranslationY(initialPositionY);
}