工具栏上滚动RecyclerView离开白色的空间隐藏 [英] Toolbar leaving white space with hide on RecyclerView scroll

查看:377
本文介绍了工具栏上滚动RecyclerView离开白色的空间隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图隐藏我的工具栏上的RecyclerView滚动,到目前为止,它似乎已经隐藏,但它留下白色的空白吧。我是pretty相信这已经是与我MainActivity布局的覆盖,并在的FrameLayout片段。

I'm trying to hide my Toolbar on the RecyclerView scroll and so far it seems to have hidden, but it's leaving a white blank with it. I'm pretty sure this has something to do with the overlay of my MainActivity's layout and the fragment in the FrameLayout.

下面是我的 activity_main.xml中。我需要的FrameLayout,因为我加载不同片段在导航抽屉的项目选择。

Here is my activity_main.xml. I need the FrameLayout because I am loading different fragments with selection of an item in the Navigation Drawer.

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:elevation="7dp"
    tools:context=".MainActivity"
    android:fitsSystemWindows="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <include layout="@layout/toolbar" />

        <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#FFFFFF" />

    </LinearLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/header"
        app:menu="@menu/drawer" />

</android.support.v4.widget.DrawerLayout>

这是包含RecyclerView片段的code。

And here is the code in the fragment that contains the RecyclerView.

...
@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View v = inflater.inflate(R.layout.fragment_main, container, false);

        getActivity().setTitle("Unit One");

        rv = (RecyclerView) v.findViewById(R.id.rv);
        rv.setHasFixedSize(true);

        llm = new LinearLayoutManager(getActivity());
        rv.setLayoutManager(llm);

        initializeData();
        initializeAdapter();

        rv.addOnScrollListener(showHideToolbarListener = new RecyclerViewUtils.ShowHideToolbarOnScrollingListener(MainActivity.toolbar));

        if (savedInstanceState != null) {
            showHideToolbarListener.onRestoreInstanceState((RecyclerViewUtils.ShowHideToolbarOnScrollingListener.State) savedInstanceState
                    .getParcelable(RecyclerViewUtils.ShowHideToolbarOnScrollingListener.SHOW_HIDE_TOOLBAR_LISTENER_STATE));
        }

        return v;
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        outState.putParcelable(RecyclerViewUtils.ShowHideToolbarOnScrollingListener.SHOW_HIDE_TOOLBAR_LISTENER_STATE,
                showHideToolbarListener.onSaveInstanceState());
        super.onSaveInstanceState(outState);
    }

最后,在RecyclerView布局 fragment_main.xml

 <android.support.v7.widget.RecyclerView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingLeft="8dp"
        android:paddingRight="8dp"
        android:orientation="vertical"
        android:scrollbars="vertical"
        android:id="@+id/rv" />

这是一个跟进我的其他帖子,但我想问一个新的问题,因为我想一个<一个href=\"http://rylexr.tinbytes.com/2015/04/27/how-to-hideshow-android-toolbar-when-scrolling-google-play-musics-behavior/\"相对=nofollow>不同的方法这一次(不读了整个帖子,看到底部的编辑)。下面是他的<一个href=\"https://github.com/rylexr/android-show-hide-toolbar/blob/master/app/src/main/java/com/tinbytes/samples/showhidetoolbar/MainActivity2.java\"相对=nofollow> MainActivity 和实际<一个href=\"https://github.com/rylexr/android-show-hide-toolbar/blob/master/app/src/main/java/com/tinbytes/samples/showhidetoolbar/util/RecyclerViewUtils.java\"相对=nofollow>滚动监听器code 。

This is a follow up to my other post, but I wanted to ask a new question since I'm trying a different method this time (don't read the entire post, see the edit at the bottom). Here is his MainActivity and the actual scrolling listener code.

我道歉,如果这似乎像我说这是我的屎去解决它,但我已经花了近两个小时寻找可能的解决办法了这一点。 与往常一样,我AP preciate的帮助很大。

I apologize if this seems like me saying "here's my shit go fix it" but I've spent almost two hours searching for a possible solution to this. As always, I appreciate the help greatly.

推荐答案

我觉得translateY,您使用的是动画工具栏,而只转移什么的在屏幕上绘制,而不是本身的视图位置。这意味着,拿着工具栏的看法仍然占有空间的线性布局顶部。

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.

使用相同的布局他用他的<一个href=\"https://github.com/rylexr/android-show-hide-toolbar/blob/master/app/src/main/res/layout/main_activity.xml\"相对=nofollow> main_activity.xml 。
您还可以使用的FrameLayout。重要的是,你把工具栏上的RecyclerView的顶部(下图中的XML),并添加一个顶部填充到RecyclerView等于工具栏的高度。

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
  ..... />

这篇关于工具栏上滚动RecyclerView离开白色的空间隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆