CollapsingToolbar没有通过ViewPager折叠..?

时间:2016-10-15 09:34:41

标签: android scroll android-recyclerview vertical-scrolling

  

我的XML布局是这样的:

<DrawerLayout>

             <CoordinatorLayout>

                          <AppBarLayout>

                                 <CoolapsingToolbarLayout>
  

ViewPager有一个Char nothing Special

                                          <ViewPager>
                                       ---------------
                                          </ViewPager

                                          <Toolbar>
                                       ---------------
                                          </Toolbar>


                                </CoolapsingToolbarLayout>


                            </AppBarLayout>
  

RecyclerView具有布局行为:&#34; app:layout_behavior =&#34; @ string / appbar_scrolling_view_behavior&#34;

                      <RecyclerView>
                   -------------------
                   -------------------
                   app:layout_behavior="@string/appbar_scrolling_view_behavior

                      </RecyclerView>


               <FloatingActionButton>
               ----------------------
               ----------------------
               </FloatingActionButton>


         </CoordinatorLayout>
  

NavigationDrawer的片段

     <fragment------
  --------------/>

 </DrawerLayout>

2 个答案:

答案 0 :(得分:0)

向您的CollapsingToolbarLayout添加一些滚动标记,例如:

app:layout_scrollFlags="scroll|exitUntilCollapsed"

答案 1 :(得分:0)

  

这是布局代码

<android.support.v4.widget.DrawerLayout
android:id="@+id/home_drawer"
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"
tools:context="com.androidforfun.divyam.homie.main_app.HomeActivity"
android:layout_height="match_parent"
android:layout_width="match_parent">

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/coordinator_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="325dp"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:elevation="7dp">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <android.support.v4.view.ViewPager
                android:id="@+id/main_viewpager"
                android:tag="main_pager"
                android:layout_marginTop="60dp"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_collapseMode="pin"/>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/colorPrimary"
                android:elevation="7dp"
                app:layout_collapseMode="pin"
                app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

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

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

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycle_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/floating_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:src="@drawable/ic_add_white"
        app:layout_anchor="@id/appbar"
        app:layout_anchorGravity="bottom|right" />


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

<fragment
    android:id="@+id/nav_fragment"
    android:layout_width="230dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:name="com.androidforfun.divyam.homie.fragments.NavDrawerFragment"
    tools:layout="@layout/fragment_nav_drawer" />

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