Toolbar leaving white space with hide on RecyclerView scroll

[亡魂溺海] 提交于 2019-11-30 22:48:43

I think that translateY, which you're using to animate the toolbar, only shifts what's drawn on the screen and not the view location itself. That means that the view holding the toolbar still occupies that space at the top in the linear layout.

Use the same layout he's using in his main_activity.xml. You can also use a FrameLayout. The important thing is that you put the toolbar on top of the RecyclerView (below in the xml) and add a top padding to the RecyclerView equal to the toolbar height.

<android.support.v7.widget.RecyclerView
  android:clipToPadding="false"
  android:paddingTop="?attr/actionBarSize" />

<android.support.v7.widget.Toolbar
  ..... />

The best approach is to use the new Design Support Library and its CoordinatorLayout:

<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.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <android.support.v7.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:layout_scrollFlags="scroll|enterAlways" />
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

For more example, you can get inspired by Chris Banes' demo application CheeseSquare or by this tutorial.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!