如何使用RecyclerView使用DrawerLayout,Toolbar和ViewPager折叠布局中的工具栏?

时间:2016-08-02 13:07:59

标签: android android-layout android-coordinatorlayout

尽管有很多关于这个问题的问题,但它们似乎都没有帮助我(我已经尝试了大部分被广告但仍然无法使其发挥作用)。我的布局如下:

<?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/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

        <android.support.design.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.design.widget.AppBarLayout
                android:id="@+id/toolbar_wrapper"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fitsSystemWindows="true">

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

                <com.ogaclejapan.smarttablayout.SmartTabLayout
                    android:id="@+id/tabs"
                    android:layout_width="match_parent"
                    android:layout_height="40dip"
                    android:layout_weight="1"
                    android:clickable="true"
                    app:stl_defaultTabTextAllCaps="true"
                    app:stl_defaultTabTextColor="#000"
                    app:stl_defaultTabTextHorizontalPadding="0dip"
                    app:stl_defaultTabTextMinWidth="0dp"
                    app:stl_defaultTabTextSize="14sp"
                    app:stl_distributeEvenly="true"
                    app:stl_drawDecorationAfterTab="true"
                    app:stl_indicatorColor="@android:color/white"
                    app:stl_indicatorGravity="bottom"
                    app:stl_indicatorInFront="false"
                    app:stl_indicatorInterpolation="smart"
                    app:stl_indicatorThickness="2dp"
                    app:stl_overlineThickness="0dp"
                    app:stl_titleOffset="24dp"
                    app:stl_underlineThickness="0dp" />
            </android.support.design.widget.AppBarLayout>
        </android.support.design.widget.CoordinatorLayout>

        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@null"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    </LinearLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/rsc_homepage_drawer_layout_content"
        app:menu="@menu/drawer_itens" />
</android.support.v4.widget.DrawerLayout>

每个片段都有一个RecyclerView。问题是什么?滚动RecyclerView时没有任何反应。如果我滚动工具栏然后隐藏,将RecyclerView保持在原始位置。任何帮助表示赞赏!

更新

以下是我的所有片段:

片段1

<RelativeLayout>
    <RelativeLayout>
        <android.support.v7.widget.CardView>
            <LinearLayout>
                <TextView/>
                <TextView />
            </LinearLayout>
        </android.support.v7.widget.CardView>

        <com.mikhaellopez.circularimageview.CircularImageView/>
    </RelativeLayout>

    <LinearLayout>
        <TextView />
        <TextView />
        <TextView />
    </LinearLayout>
</RelativeLayout>

<android.support.v7.widget.CardView>
    <TextView/>
</android.support.v7.widget.CardView>

<android.support.v7.widget.RecyclerView" />

片段2

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@null">

....

<RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <android.support.v7.widget.CardView
                android:id="@+id/not_results_found_wrapper"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:alpha="0.95"
                android:elevation="4dip"
                android:visibility="gone"
                card_view:cardBackgroundColor="@android:color/white"
                card_view:cardCornerRadius="5dp"
                card_view:cardUseCompatPadding="true">

                <TextView
                    android:id="@+id/not_results_found"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:padding="10dip"
                    android:text="@string/rsc_search_friends_no_results_founds"
                    android:textColor="@color/colorPrimaryDark"
                    android:textSize="@dimen/textH3"
                    android:textStyle="bold" />
            </android.support.v7.widget.CardView>

            <android.support.v7.widget.RecyclerView
                android:id="@+id/result"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@+id/not_results_found_wrapper"
                android:layout_marginEnd="10dip"
                android:layout_marginStart="10dip"
                android:layout_marginTop="5dip"
                android:overScrollMode="never" />
        </RelativeLayout>
</ScrollView>

片段3

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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent"
    android:orientation="vertical">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/chats"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:overScrollMode="never" />

    <android.support.v7.widget.CardView
        android:id="@+id/msg_wrapper"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_margin="30dip"
        android:alpha="0.95"
        android:elevation="4dip"
        card_view:cardBackgroundColor="@android:color/white"
        card_view:cardCornerRadius="5dp"
        card_view:cardUseCompatPadding="true">

        <TextView
            android:id="@+id/results_not_found"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:gravity="center"
            android:layout_margin="15dip"
            android:text="@string/frag_chats_no_chat_use"
            android:textAlignment="center"
            android:textColor="@color/colorPrimaryDark"
            android:textSize="@dimen/textH2"
            android:textStyle="bold" />
    </android.support.v7.widget.CardView>
</RelativeLayout>

片段4

<?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:fab="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/games"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/toolbar_wrapper"
        android:overScrollMode="never"/>

    <com.melnykov.fab.FloatingActionButton
        android:id="@+id/add_game"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right"
        android:layout_margin="16dip"
        android:clickable="true"
        android:src="@drawable/ic_plus_white_24dp"
        app:borderWidth="0dp"
        app:elevation="4dp"
        app:layout_anchor="@id/games"
        app:layout_anchorGravity="bottom|right|end"
        fab:fab_colorNormal="@color/colorPrimary"
        fab:fab_colorPressed="@color/colorPrimaryDark" />
</android.support.design.widget.CoordinatorLayout>

1 个答案:

答案 0 :(得分:1)

尝试将RecyclerView放入NestedScrollView

这样的事情:

<android.support.v4.widget.NestedScrollView
    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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

<android.support.v7.widget.RecyclerView
    android:id="@+id/my_recycler_view"
    android:scrollbars="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>