Layout
<android.support.design.widget.coordinatorlayout
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent" >
<include layout= "@layout/toolbar"/>
<include layout= "@layout/container"/>
<android.support.design.widget.bottomnavigationview
Android:id= "@+id/bottom_navigation"
style= "@style/widget.design.bottomnavigationview"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
Android:layout_alignparentbottom= "true"
android:layout_gravity= "Bottom"
android:background= "@color/viewbackground"
app:elevation= "16DP"
app:itemicontint= "@drawable/nav_item_color_state"
App:itemtextcolor= "@drawable/nav_item_color_state"
App:layout_behavior= "Com.meiji.toutiao.widget.behavior.BottomNavigationBehavior"
app:menu= "@menu/bottom_navigation_main"/>
Android BC Credit Disk build dsluntan.com vx:17061863513 custom behavior implement up slide hide bottom view
BC Credit Disk Build dsluntan.com vx:17061863513
Above is the layout code of Activity_main, the first is the menu bar, the second is the content interface, the third is bottom. Bottom navigation bar is used here is Bottomnavigationview, the specific usage is not introduced.
Here's a look at the App:layout_behavior property of Bottomnavigationview, which is unique to the coordinated layout. Online version of the usage is app:layout_behavior= "@string/appbar_scrolling_view_behavior"
Although the surface is a string, in fact, the call is also a view class. This time we are customizing this behavior class to realize the implicit display of the bottom menu bar.
Java Implementation Classes
public class Bottomnavigationbehavior extends Coordinatorlayout.behavior<view> {
Private Objectanimator outanimator, Inanimator;
Public Bottomnavigationbehavior (context context, AttributeSet Attrs) {
Super (context, attrs);
}
Vertical Slide
@Override
public boolean onstartnestedscroll (Coordinatorlayout coordinatorlayout, view child, view directtargetchild, view target , int nestedscrollaxes) {
return nestedscrollaxes = = viewcompat.scroll_axis_vertical;
}
@Override
public void Onnestedprescroll (Coordinatorlayout coordinatorlayout, view child, view target, int dx, int dy, int[] consumed ) {
if (Dy > 0) {//Slide up Hide
if (Outanimator = = null) {
Outanimator = Objectanimator.offloat (Child, "Translationy", 0, Child.getheight ());
Outanimator.setduration (200);
}
if (!outanimator.isrunning () && child.gettranslationy () <= 0) {
Outanimator.start ();
}
} else if (Dy < 0) {//Slide show
if (Inanimator = = null) {
Inanimator = Objectanimator.offloat (Child, "Translationy", Child.getheight (), 0);
Inanimator.setduration (200);
}
if (!inanimator.isrunning () && child.gettranslationy () >= child.getheight ()) {
Inanimator.start ();
}
}
}
}
This class is just the class of the app:layout_behavior= "Com.meiji.toutiao.widget.behavior.BottomNavigationBehavior" attribute, it looks very simple, Inherits the behavior abstract class, and then implements two methods. Take a look at how the source code explains
Onstartnestedscroll: This method is primarily used to monitor the scrolling events of a coordinated layout's sub-view, when this method returns true, means to consume this action, and then executes the following Onnestedprescroll method, which we return in the code, The scroll axis is not a vertical scroll axis. If it is, it returns true.
Onnestedprescroll: This method is relatively simple, when the user on the slide, hide the bottom menu bar, where the use of animation exit, using the Objectanimator.offloat method, the first is a View object, refers to the bottom, The second is the y-axis change, the third is how much the y-axis changes, and the next set of animation seconds.
Android BC Credit Disk build custom behavior implement up slide hide bottom view