2016-08-02 87 views
1

虽然关于这个问题有很多问题,但他们没有一个似乎帮助我(我尝试了大部分的东西,但仍然无法使它工作)。我的布局如下:如何在具有DrawerLayout,工具栏和ViewPager的布局中折叠工具栏与RecyclerView?

<?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在原来的位置。任何帮助表示赞赏!

UPDATE

以下是所有我的片段:

片段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> 
+0

删除'应用程式:layout_behavior = “@串/ appbar_scrolling_view_behavior”''从和ViewPager'到您的片段(RecyclerView的父视图)的每个父。 –

+0

同样的事情。我刚刚意识到的是,我的两个片段由父组件构成一个ScrollView和另一个CoordinatorLayout。那是问题吗? –

+0

是的,滚动视图将限制工具栏的折叠。因此要么使用'app:layout_behavior =“@ string/appbar_scrolling_view_behavior”'或者根本不提供父级,并使用'layout_behaviour'标志以上的回收站视图为您的recyclerview提供线性或相对布局。 –

回答

1

尝试把你的RecyclerViewNestedScrollView

像这样:

<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"/> 
+0

不幸的是,没有任何改变 –