【问题标题】:how to hide toolbar on scroll when using recyclerView inside NestedScrollView在 NestedScrollView 中使用 recyclerView 时如何在滚动时隐藏工具栏
【发布时间】:2017-03-02 15:19:40
【问题描述】:

我正在使用 NestedScrollView,它用于在滚动时隐藏工具栏,但是当我放 里面的recyclerView,工具栏没有隐藏在滚动上,我在stackoverflow中使用了所有可能的答案,但没有任何效果,特别是我使用了recyclerView.setNestedScrollingEnabled(false);

这是我的代码:

<android.support.v4.widget.NestedScrollView 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"

    app:layout_behavior="@string/appbar_scrolling_view_behavior">

<RelativeLayout

    android:layout_width="match_parent"
    android:background="#fff"
    android:layout_height="wrap_content"
    >



    <android.support.v7.widget.RecyclerView



        android:id="@+id/recyclerView"
        android:background="#fafafa"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true" />

    <ProgressBar
        android:id="@+id/progressBar1"

        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" />

</RelativeLayout>

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

--- 编辑-----------

<?xml version="1.0" encoding="utf-8"?>


<android.support.v4.widget.DrawerLayout

    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/DrawerLayout"

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:elevation="7dp">
    <include
        android:id="@+id/includeAppBar"
        layout="@layout/app_bar_navigation_drawer"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />


    <android.support.v7.widget.RecyclerView
        android:id="@+id/RecyclerView"
        android:layout_width="320dp"
        android:layout_height="match_parent"
        android:layout_gravity="left"

        android:background="#ffffff"
        android:scrollbars="vertical">

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

----编辑 2----

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:theme="@style/ThemeOverlay.AppCompat.Dark">
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            app:theme="@style/ToolBarStyle"
            app:layout_scrollFlags="scroll|enterAlways"
            android:layout_height="?attr/actionBarSize"
            />


        <!-- our tablayout to display tabs  -->
        <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#fff"
            app:tabTextColor="#a6a2a2"
            app:tabSelectedTextColor="#0099ff"
            app:tabIndicatorColor="#0099ff"


            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
    </android.support.design.widget.AppBarLayout>
    <!-- View pager to swipe views -->
    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"/>






</android.support.design.widget.CoordinatorLayout>

【问题讨论】:

  • 你好,你能把xml代码分享给你的工具栏吗
  • 嘿,看看我的编辑问题。
  • 能否也显示 app_bar_navigation_drawer 布局?
  • 查看我的编辑 2 问题

标签: android android-recyclerview android-nestedscrollview


【解决方案1】:

你可以试试这个,把这个属性添加到你的 AppBarLayout 中:

app:layout_scrollFlags="scroll|exitUntilCollapsed"

编辑:

也将您的代码更改如下:

<?xml version="1.0" encoding="utf-8"?>


<android.support.v4.widget.DrawerLayout

    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/DrawerLayout"

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:elevation="7dp">
    <include
        android:id="@+id/includeAppBar"
        layout="@layout/app_bar_navigation_drawer"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />


    <android.support.v7.widget.RecyclerView
        android:id="@+id/RecyclerView"
        android:layout_width="320dp"
        android:layout_height="match_parent"
        android:layout_gravity="left"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" // new attibute
        android:background="#ffffff"
        android:scrollbars="vertical">

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

希望这会有所帮助。

对不起我的英语。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多