Bog*_*rac 2 android android-layout android-support-library android-support-design
BottomNavigationView
向下滚动时,支持库v25.0.0中的新内容应该隐藏,以便查看列表中的所有项目.但是,在我的测试场景中,视图在向上滚动时隐藏.什么可以导致这种反向行为的想法?
它inner_fragment
被设置为插入activity_main_framelayout_content
Framelayout 内的片段.XML布局如下:
main_activity.xml:
<android.support.design.widget.CoordinatorLayout
android:id="@+id/activity_main_coordinatorlayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/activity_main_appbarlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/activity_main_toolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
android:background="?attr/colorPrimary"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways">
<include layout="@layout/activity_main_spinner_layout"/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/activity_main_framelayout_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:fitsSystemWindows="true"/>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="@+id/activity_main_framelayout_navigation_drawer"
android:layout_width="@dimen/drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
android:background="@color/color_black_700"/>
Run Code Online (Sandbox Code Playgroud)
inner_fragment.xml:
<FrameLayout 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/inner_fragment_framelayout"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<android.support.design.widget.BottomNavigationView
android:id="@+id/inner_fragment_bottom_navigation_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:menu="@menu/inner_fragment"
app:itemBackground="@drawable/bg_bottom_navigation"
app:itemIconTint="@color/ic_bottom_navigation"
app:itemTextColor="@color/ic_bottom_navigation"/>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
此版本的BottomNavigationView缺少滚动行为,无法按照指南中的说明开箱即用.
我写了一篇关于缺少什么以及如何修复它的文章.这包括在CoordinatorLayout中实现BottomNavigationView的滚动行为.
一个简单的解决方案是向appbarlayout添加一个偏移侦听器.适合我.
所以像这样:
((AppBarLayout)toolbar.getParent()).addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
mNavigationBar.setTranslationY(verticalOffset*-1);
}
});
Run Code Online (Sandbox Code Playgroud)