How to make it so that when the page is scrolled down, the lower toolbar will go up, and when you will go up, it would go down (we are talking about toolbar2)

XML:

<android.support.design.widget.CoordinatorLayout android:id="@+id/main_content" 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" xmlns:tools="http://schemas.android.com/tools"> <include layout="@layout/tollbar_post" /> <android.support.v4.widget.NestedScrollView android:id="@+id/scroll" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <LinearLayout android:id="@+id/app_linear_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:gravity="center_horizontal|center" android:orientation="vertical"> </LinearLayout> </android.support.v4.widget.NestedScrollView> <android.support.v7.widget.Toolbar android:id="@+id/toolbar2" android:layout_width="match_parent" android:layout_height="?android:actionBarSize" android:layout_gravity="bottom" android:background="@color/cardview_shadow_start_color" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" app:contentInsetEnd="0dp" app:contentInsetLeft="0dp" app:contentInsetRight="0dp" app:contentInsetStart="0dp" app:layout_behavior="ru.stopgame.artem.stopgame.utility.ScrollingToolbarBehavior"> <LinearLayout android:layout_width="match_parent" android:layout_height="20dp" android:orientation="horizontal"> <ImageView android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="2dp" app:srcCompat="@drawable/ic_launcher" /> <TextView android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" /> <TextView android:id="@+id/date" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" /> <TextView android:id="@+id/views" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" /> <TextView android:id="@+id/komments" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/printing" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="2dp" android:layout_weight="1" android:linksClickable="true" /> </LinearLayout> </android.support.v7.widget.Toolbar> 

Code:

 class ScrollingToolbarBehavior extends CoordinatorLayout.Behavior<Toolbar> { public ScrollingToolbarBehavior(Context context, AttributeSet attrs) { super(context, attrs); } @Override public boolean layoutDependsOn(CoordinatorLayout parent, Toolbar child, View dependency) { return dependency instanceof AppBarLayout; } @Override public boolean onDependentViewChanged(CoordinatorLayout parent, Toolbar child, View dependency) { if (dependency instanceof AppBarLayout) { int distanceToScroll = child.getHeight(); int bottomToolbarHeight = child.getHeight();//TODO replace this with bottom toolbar height. float ratio = dependency.getY() / (float) bottomToolbarHeight; child.setTranslationY(-distanceToScroll * ratio); } return true; } } 

Lower the toolbar does not work, so he just went up

  • app:layout_collapseMode="pin" ? - McDaggen
  • @McDaggen added to the toolbar, and did not help ( - chilo5432

0