Android BottomNavigationView 对 SlidingUpPanelLayout 运动做出反应



我一直在尝试在com.sothree.slidinguppanel.SlidingUpPanelLayout运动上制作一些BottomNavigationView的动画。 这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.sothree.slidinguppanel.SlidingUpPanelLayout
android:id="@+id/slidingUpPanel"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.test.activity.MainActivity"
tools:showIn="@layout/activity_main"
android:gravity="bottom"
android:layout_above="@+id/bottom_nav_view"
app:umanoPanelHeight="50dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android: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"/>
</RelativeLayout>
<fragment
android:id="@+id/invitationFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.test.fragment.CustomListFragment" />
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
<android.support.design.widget.BottomNavigationView
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" />
</RelativeLayout>

我也一直在尝试将 CoordinatorLayout 作为顶部视图与扩展 CoordinatorLayout.Behavior 的 BottomNavigationViewBehavior 合并在一起,但没有成功。

我也一直在尝试收听面板上的事件(slidingUpPanelLayout.setOnScrollChangeListener & slidingUpPanelLayout.setOnDragListener(,但遗憾的是它们从未被调用。

我正在使用以下版本:

  • 安卓支持库 25.3.1
  • com.sothree.slidinguppanel:library:3.3.0

这个想法是使底部栏的行为与soundcloud应用程序中完全相同(soundcloud正在使用com.sothree.slidinguppanel lib(。

谢谢。

我终于使用 BottomSheetBehavior + 它的回调来制作 BotomNavigationBar 的动画。 这是布局:

<RelativeLayout
xmlns: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">
<FrameLayout
android: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.CoordinatorLayout
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android: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">
<fragment
android: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.BottomNavigationView
android: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>

和相关代码: 我有可能使用扩展BottomSheetBehavior的customBehavior,或者只是听BottomSheetCallback,我选择了第二个解决方案:

回调:

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);
}
});

平滑动画(向上滚动底部工作表时底部导航栏向下,反之亦然(:

private void slideDown(BottomNavigationView child, float slideOffset) {
float heigh_to_animate = slideOffset * child.getHeight();
ViewPropertyAnimator animator = child.animate();
animator
.translationY(heigh_to_animate)
.setInterpolator(new DecelerateInterpolator())
.setDuration(0)
.start();
}

最新更新