public class ConstraintLayoutBehavior extends CoordinatorLayout.Behavior<ConstraintLayout> {
public ConstraintLayoutBehavior(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
}
@Override
public boolean layoutDependsOn(CoordinatorLayout parent, ConstraintLayout child, View dependency) {
return dependency instanceof Snackbar.SnackbarLayout;
}
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, ConstraintLayout child, View dependency) {
float translationY = Math.min(0, dependency.getTranslationY() - dependency.getHeight());
child.setTranslationY(translationY);
return true;
}
@Override
public void onDependentViewRemoved(CoordinatorLayout parent, ConstraintLayout child, View dependency) {
child.setTranslationY(0);
}
}