android - How to reset the Toolbar position controlled by the CoordinatorLayout? -
the app i'm working on consists of navigation drawer implemented in activity. activity layout follows:
<framelayout 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"> <android.support.v4.widget.drawerlayout android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.design.widget.coordinatorlayout android:id="@+id/coordinator" android:layout_width="match_parent" android:layout_height="match_parent"> <framelayout android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <include android:id="@+id/appbar" layout="@layout/appbar" /> </android.support.design.widget.coordinatorlayout> <android.support.design.widget.navigationview android:id="@+id/navigation_drawer" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="start" app:headerlayout="@layout/header_drawer" app:menu="@menu/menu_nav"> </android.support.design.widget.navigationview> </android.support.v4.widget.drawerlayout> </framelayout>
this common pattern, thing changes fragment inside container layout.
if of fragment has scrolling element, upon scrolling, coordinatorlayout happily make position translations, including toolbar/appbarlayout.
the real problem here is, when fragment gets replaced, position toolbar remains same, i.e., if toolbar hidden, stay isn't intended.
result this:
this:
gets stuck:
how can 1 reset toolbar position case?
edit: bug probable, appbarlayout offset change listener gets called when relaunching app (press button , open app), , stops getting called again after intense fling.
to reset scroll state, appbarlayout.behavior
object
coordinatorlayout coordinator = (coordinatorlayout) findviewbyid(r.id.coordinator); appbarlayout appbar = (appbarlayout) findviewbyid(r.id.appbar); coordinatorlayout.layoutparams params = (coordinatorlayout.layoutparams) appbar.getlayoutparams(); appbarlayout.behavior behavior = (appbarlayout.behavior) params.getbehavior();
and call onnestedprescroll
method manually:
int[] consumed = new int[2]; behavior.onnestedprescroll(coordinator, appbar, null, 0, -1000, consumed);
if reset smoothly animation, can try calling onnestedfling
instead:
behavior.onnestedfling(coordinator, appbar, null, 0, -1000, true);
Comments
Post a Comment