Skip to content Skip to sidebar Skip to footer

Android Bottomnavigationview React To Slidinguppanellayout Mouvements

I've been trying to animate some BottomNavigationView depdending on com.sothree.slidinguppanel.SlidingUpPanelLayout mouvements. here is my layout :

Solution 1:

I finally used BottomSheetBehavior + its callback to animate the BotomNavigationBar. here is the layout :

<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:layout_width="match_parent"android:layout_height="match_parent"><FrameLayoutandroid:id="@+id/fragment_container"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_marginLeft="@dimen/activity_horizontal_margin"android:layout_marginRight="@dimen/activity_horizontal_margin"></FrameLayout><android.support.design.widget.CoordinatorLayoutandroid:id="@+id/coordinator_layout"android:layout_width="match_parent"android:layout_height="match_parent"><LinearLayoutandroid:background="@color/light_grey"android:id="@+id/bottom_sheet"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"android:fitsSystemWindows="true"app:layout_behavior="android.support.design.widget.BottomSheetBehavior"app:behavior_hideable="true"app:behavior_peekHeight="120dp"><fragmentandroid:id="@+id/invitationFragment"android:layout_width="match_parent"android:layout_height="match_parent"android:name="com.test.view.fragment.InvitationListFragment" /></LinearLayout></android.support.design.widget.CoordinatorLayout><android.support.design.widget.BottomNavigationViewandroid:background="@color/white"android:id="@+id/bottom_nav_view"android:layout_width="match_parent"android:layout_height="56dp"android:layout_alignParentBottom="true"app:itemIconTint="@drawable/item_bottom_bar_bg"app:itemTextColor="@drawable/item_bottom_bar_bg"app:elevation="0dp"app:menu="@menu/bottom_navigation"android:visibility="visible"/></RelativeLayout>

and the related code: I had the possibility to use a customBehaviour extending BottomSheetBehavior or simply listen to BottomSheetCallback, i went for the 2nd solution:

callback :

bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
        @Override
        public void onStateChanged(@NonNull View bottomSheet, int newState) {
        }

        @Override
        public void onSlide(@NonNull View bottomSheet, float slideOffset) {
            slideDown(bottomNavigationView,slideOffset);
        }
    });

smooth animation (the BottomNavigationBar goes down while scrolling the BottomSheet up and vice versa):

privatevoidslideDown(BottomNavigationView child, float slideOffset) {
    floatheigh_to_animate= slideOffset * child.getHeight();
    ViewPropertyAnimatoranimator= child.animate();
    animator
            .translationY(heigh_to_animate)
            .setInterpolator(newDecelerateInterpolator())
            .setDuration(0)
            .start();
}

Post a Comment for "Android Bottomnavigationview React To Slidinguppanellayout Mouvements"