【问题标题】:CollapsingToolbar not Collapsing through ViewPager ..?CollapsingToolbar 不通过 ViewPager 折叠 ..?
【发布时间】:2016-10-15 09:34:40
【问题描述】:

我的 XML 布局是这样的:

<DrawerLayout>

             <CoordinatorLayout>

                          <AppBarLayout>

                                 <CoolapsingToolbarLayout>

ViewPager 没有什么特别的字符

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

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


                                </CoolapsingToolbarLayout>


                            </AppBarLayout>

RecyclerView 具有布局行为:“app:layout_behavior="@string/appbar_scrolling_view_behavior"

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

                      </RecyclerView>


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


         </CoordinatorLayout>

NavigationDrawer 的片段

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

 </DrawerLayout>

【问题讨论】:

    标签: android scroll android-recyclerview vertical-scrolling


    【解决方案1】:

    这是布局代码

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

    【讨论】:

      【解决方案2】:

      在 CollapsingToolbarLayout 中添加一些滚动标志,例如:

      app:layout_scrollFlags="scroll|exitUntilCollapsed"
      

      【讨论】:

      • ok 试试这些:1)清理项目并构建它,这有时对我有用。 2)尝试删除视图寻呼机。 3) 尝试使用 NestedScrollView 而不是 RecyclerView,仅用于测试目的。
      • 试过没用..??你知道有什么问题吗,我认为这是因为 DrawerLayout 是父级,并且导致 CoordinatorLayout 无法正常运行..
      • 不,我不认为这是问题所在,DrawerLayout 可以是 CoordinatorLayout 的父级,没有任何问题。我的应用里有这个
      • 请发布完整版面
      • 但我在我的博客中看到他们说始终让 Coordinator Layout 成为您的父 Layout 很重要..
      猜你喜欢
      • 1970-01-01
      • 2015-10-30
      • 1970-01-01
      • 2021-03-10
      • 1970-01-01
      • 1970-01-01
      • 2017-06-01
      • 2015-09-16
      • 2015-11-02
      相关资源
      最近更新 更多