代码之家  ›  专栏  ›  技术社区  ›  Happo

Android QuickReturn模式和RecyclerView

  •  2
  • Happo  · 技术社区  · 8 年前

    我想在RecyclerView上方放置一个视图,该视图使用RecyclerView滚动,并使用向下滚动立即向下滚动。我知道这种行为是快速返回,但它是为Listview实现的。我知道可以使用CoordinatorLayout进行一些类似的操作,但所有示例都使用工具栏进行操作。我想要的是在eBay应用程序中完成。

    enter image description here

    2 回复  |  直到 8 年前
        1
  •  3
  •   Cheticamp    8 年前

    您需要设置 CoordinatorLayout 带有嵌入式 AppBarLayout 包含 CollapsingToolbarLayout 包裹着一个 Toolbar 还有一个兄弟姐妹 ViewGroup 例如 LinearLayout . 是兄弟姐妹 视图组 将滑到工具栏后面。另一个键是在 折叠工具栏布局 scroll|exitUntilCollapsed|enterAlways .

    以下是结果的简短视频:

    enter image description here

    以下是XML:

    <android.support.design.widget.CoordinatorLayout 
        android:id="@+id/coordinatorLayout"
        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="wrap_content"
            android:fitsSystemWindows="true"
            android:theme="@style/AppTheme.AppBarOverlay"
            app:expanded="true">
    
            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsingToolbarLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_scrollFlags="scroll|exitUntilCollapsed|enterAlways"
                app:statusBarScrim="?attr/colorPrimaryDark">
    
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:layout_marginTop="?attr/actionBarSize"
                    android:background="@color/colorAccent"
                    android:orientation="vertical"
                    app:layout_collapseMode="parallax"
                    app:layout_collapseParallaxMultiplier="0.0">
    
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="This is line #1 of the sliding layout..." />
    
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="This is line #2 of the sliding layout..." />
                </LinearLayout>
    
                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:background="@color/colorPrimary"
                    app:layout_collapseMode="pin" />
    
            </android.support.design.widget.CollapsingToolbarLayout>
    
        </android.support.design.widget.AppBarLayout>
    
        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            tools:context="example.com.myapp.ScrollingActivity"
            tools:showIn="@layout/activity_scrolling">
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="@dimen/text_margin"
                android:text="@string/large_text" />
    
        </android.support.v4.widget.NestedScrollView>
    
    </android.support.design.widget.CoordinatorLayout>
    
        2
  •  0
  •   Ofek Regev    8 年前

    尝试使用ScrollView包装RcyclerView和QuickReturn布局。

    用于平滑滚动使用-

    recyclerview.setFocusable(false);
    recyclerview.setNestedScrollingEnabled(false);