0

Ich möchte BottomNavigationView beim Blättern der Seite ausblenden. Ich habe diesen Code gefunden. Ich möchte dies auf BottomNavigationView anwenden. So finden Sie BottomNavigationView mithilfe des Koordinatorlayouts.So wenden Sie das benutzerdefinierte Koordinatorverhalten auf die untere Navigationsansicht an

class BottomNavigationBehavior extends CoordinatorLayout.Behavior<BottomNavigationView> { 
 

 
    public BottomNavigationBehavior() { 
 
     super(); 
 
    } 
 

 
    public BottomNavigationBehavior(Context context, AttributeSet attrs) { 
 
     super(context, attrs); 
 
    } 
 

 
    @Override 
 
    public boolean layoutDependsOn(CoordinatorLayout parent, BottomNavigationView child, View dependency) { 
 
     boolean dependsOn = dependency instanceof FrameLayout; 
 
     return dependsOn; 
 
    } 
 

 
    @Override 
 
    public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, BottomNavigationView child, View directTargetChild, View target, int nestedScrollAxes) { 
 
     return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL; 
 
    } 
 

 
    @Override 
 
    public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, BottomNavigationView child, View target, int dx, int dy, int[] consumed) { 
 
     if (dy < 0) { 
 
      showBottomNavigationView(child); 
 
     } else if (dy > 0) { 
 
      hideBottomNavigationView(child); 
 
     } 
 
    } 
 

 
    private void hideBottomNavigationView(BottomNavigationView view) { 
 
     view.animate().translationY(view.getHeight()); 
 
    } 
 

 
    private void showBottomNavigationView(BottomNavigationView view) { 
 
     view.animate().translationY(0); 
 
    } 
 
}

Antwort

0

app:layout_behavior="path_to_your_custom_behavior_class" 

zum Layout-XML-Code hinzufügen.

Verwandte Themen