我正在开发一个以fab为中心的bottomnavigationview的应用程序。当我像浮游的app一样滚动时,我需要隐藏整个视图(bottomview + fab)。我已附加了布局图片和xml文件.i实现了布局,但滚动时不会隐藏bottomnavigation和fab。Nowi需要隐藏滚动时隐藏的bottomnavigation和fab才能隐藏。
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:id="@+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="always"
android:scrollbarAlwaysDrawVerticalTrack="true"
tools:context=".DeliveryManLandingScreen">
<RelativeLayout
android:id="@+id/rel_lay"
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_above="@+id/rel_view">
</FrameLayout>
<View
android:id="@+id/rel_view"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_above="@+id/mainFrame"
android:layout_alignTop="@+id/mainFrame"
android:layout_marginBottom="3dp"
android:background="@color/colorPrimary" />
<android.support.design.widget.CoordinatorLayout
android:id="@+id/mainFrame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="2dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.design.widget.BottomNavigationView
android:id="@+id/itemBottomList"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@color/textColor"
android:overScrollMode="always"
app:elevation="8dp"
app:itemHorizontalTranslationEnabled="true"
app:itemIconTint="@drawable/activity_delivery_bg"
app:itemTextColor="@drawable/activity_delivery_bg"
app:labelVisibilityMode="labeled"
app:layout_behavior="android.com.foodorderapplication.BottomNavigationBehavior"
app:menu="@menu/bottom_items_navigator" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_gravity="fill_vertical"
android:layout_marginBottom="29dp"
android:background="@color/textColor"
android:backgroundTint="#f5fffa"
android:clickable="true"
android:focusable="true"
android:scaleType="centerCrop"
app:borderWidth="1dp"
app:elevation="4dp"
app:fabSize="normal"
app:rippleColor="#f5fffa"
app:srcCompat="@drawable/offers" />
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
答案 0 :(得分:0)
如果您使用RecyclerView
进行滚动,则可以尝试以下代码:
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
switch (newState) {
// you are scrolling now
case RecyclerView.SCROLL_STATE_DRAGGING:
// here your *view* should be the parent of bottom navigation and fab
TransitionManager.beginDelayedTransition(view);
// hide view
view.setVisibility(View.GONE);
break;
}
}
});
TransitionManager
将帮助您进行基本的过渡动画。
请注意,停止滚动时必须调用view.setVisibility(View.VISIBLE)
,以便再次显示底部导航