Android BottomNavigationView对SlidingUpPanelLayout运动有反应 [英] Android BottomNavigationView react to SlidingUpPanelLayout mouvements
问题描述
我一直在尝试对com.sothree.slidinguppanel.SlidingUpPanelLayout动画上的一些BottomNavigationView进行动画处理。
这是我的布局:
I've been trying to animate some BottomNavigationView depdending on com.sothree.slidinguppanel.SlidingUpPanelLayout mouvements. here is my layout :
<?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作为顶视图与BottomNavigationViewBehavior一起扩展CoordinatorLayout.Behavior,但没有
I have also been trying to incorporate a CoordinatorLayout as top view together with BottomNavigationViewBehavior extending CoordinatorLayout.Behavior but without success.
我也一直在试听面板上的事件(slidingUpPanelLayout.setOnScrollChangeListener和amp; slideUpPanelLayout.setOnDragListener),但很遗憾,它们从未被调用。
I have also been tryin to listen to events on the panel (slidingUpPanelLayout.setOnScrollChangeListener & slidingUpPanelLayout.setOnDragListener) but strangly they never get called.
我正在使用以下版本:
- android support lib 25.3.1
- com.sothree.slidinguppanel:library:3.3.0
该想法是具有完全相同的行为像在soundcloud应用程序中一样(并且soundcloud正在使用com.sothree.slidinguppanel lib)。
The idea is to have the exact same behaviour of the bottom bar as in soundcloud app. (and soundcloud is using com.sothree.slidinguppanel lib).
谢谢。
推荐答案
我最终使用BottomSheetBehavior及其回调来为BotomNavigationBar设置动画。
是布局:
I finally used BottomSheetBehavior + its callback to animate the BotomNavigationBar. here is the layout :
<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>
和相关代码:
我有可能使用customBehaviour扩展BottomSheetBehavior或简单地使用听BottomSheetCallback,我寻求第二种解决方案:
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:
回调:
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);
}
});
平滑动画(BottomNavigationBar向下滚动,同时向上滚动BottomSheet,反之亦然):
smooth animation (the BottomNavigationBar goes down while scrolling the BottomSheet up and vice versa):
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();
}
这篇关于Android BottomNavigationView对SlidingUpPanelLayout运动有反应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!