I am trying to hide or show the toolbar when the user scrolls the list. For this, I use translation, but instead of my actionBar, empty space appears. If I use setVisibility (View.GONE), the empty space will appear during the animation and hide when it is done, which is ugly.
Here is a short video about my problem
And here is how I do my animation (from a Google I / O application):
public void showToolbar(boolean show){ if (show) { toolbar.animate() .translationY(0) .alpha(1) .setDuration(HEADER_HIDE_ANIM_DURATION) .setInterpolator(new DecelerateInterpolator()); } else { toolbar.animate() .translationY(-toolbar.getBottom()) .alpha(0) .setDuration(HEADER_HIDE_ANIM_DURATION) .setInterpolator(new DecelerateInterpolator()); } }
And here is my layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/mainContent"> <include layout="@layout/toolbar" android:id="@+id/my_toolbar" /> <fragment android:name="com.ar.oe.fragments.SectionsFragment" android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="?attr/actionBarSize"/> </RelativeLayout>
And my toolbar
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/my_toolbar" android:layout_height="?attr/actionBarSize" android:layout_width="match_parent" android:minHeight="?attr/actionBarSize" android:background="?attr/colorPrimary" />
source share