How to move a view above Snackbar just like FloatingButton

前端 未结 8 561
伪装坚强ぢ
伪装坚强ぢ 2021-01-31 07:50

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?

8条回答
  •  太阳男子
    2021-01-31 08:34

    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.

提交回复
热议问题