1

私は、recyclerViewで上下にスクロールしながら、ツールバーとbottomNavigationViewの表示と非表示機能を実装しました。 これで、recyclerViewアイテムをクリックして、recyclerViewを持たない詳細ページに移動しました。今でもツールバーとbottomNavigationViewも隠されています。このフラグメントで再び可視にする方法。再度ツールバーと下部のナビゲーションビューを表示

main_activity.xml

<android.support.design.widget.CoordinatorLayout 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" 
android:orientation="vertical"> 

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/tool_bar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:elevation="5dp" 
     android:theme="@style/ToolbarTheme" 
     app:layout_scrollFlags="scroll|enterAlways" 
     app:titleTextAppearance="@style/Toolbar.TitleText" /> 
</android.support.design.widget.AppBarLayout> 

<FrameLayout 
    android:id="@+id/content_frame" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#ffffff" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    /> 


<com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx 
    android:id="@+id/bottom_navigation_bar" 
    android:layout_width="match_parent" 
    android:layout_height="56dp" 
    android:layout_alignParentBottom="true" 
    android:layout_gravity="bottom" 
    android:background="@drawable/menu_view" 
    android:isScrollContainer="false" 
    app:itemIconTint="@drawable/nav_item_color_state" 
    app:menu="@menu/my_navigation_items" /> 

BottomNavigationViewBehaviour.java

public class BottomNavigationViewBehavior extends CoordinatorLayout.Behavior<BottomNavigationView> { 

private int height; 

@Override 
public boolean onLayoutChild(CoordinatorLayout parent, BottomNavigationView child, int layoutDirection) { 
    height = child.getHeight(); 
    return super.onLayoutChild(parent, child, layoutDirection); 
} 

@Override 
public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, BottomNavigationView child, 
            View directTargetChild, View target, int nestedScrollAxes) { 
    return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL; 
} 

@Override 
public void onNestedScroll(CoordinatorLayout coordinatorLayout, BottomNavigationView child, View target, 
          int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) { 
    if (dyConsumed > 0) { 
     slideDown(child); 
    } else if (dyConsumed < 0) { 
     slideUp(child); 
    } 
} 

private void slideUp(BottomNavigationView child) { 
    child.clearAnimation(); 
    child.animate().translationY(0).setDuration(50); 
} 

private void slideDown(BottomNavigationView child) { 
    child.clearAnimation(); 
    child.animate().translationY(height).setDuration(50); 
} 

}

MainActivity.java

CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) mBottomNav.getLayoutParams(); 
    layoutParams.setBehavior(new BottomNavigationViewBehavior()); 
    mBottomNav.clearAnimation(); 
    mBottomNav.animate().translationY(mBottomNav.getHeight()).setDuration(100); 

ご協力いただければ幸いです。

答えて

1

appbarLayoutを使用してappbarLayout.setExpand(true)を使用して展開することはできますが、これはあなたのbottomNavigationbarではなくアクションバーを表示するだけです。

+0

ありがとうございます! :)これはAppbarを修正するのに役立ちますが、bottomnavigationviewは修正しません。それに対する解決策はありますか? –

関連する問題