Android 带有 RecyclerView 的 QuickReturn 模式
Android QuickReturn Pattern with RecyclerView
我想在 RecyclerView 上方放置一个视图,该视图随 RecyclerView 一起滚动,并随向下滚动立即向下滚动。我知道这种行为很快 return 但它是为 Listview 实现的。我知道可以使用 CoordinatorLayout 完成一些类似的操作,但所有示例都使用工具栏进行操作。我想要的在 eBay 应用程序中完成。
尝试使用 ScrollView 包裹 RcyclerView 和 QuickReturn 布局。
平滑滚动使用-
recyclerview.setFocusable(false);
recyclerview.setNestedScrollingEnabled(false);
您需要设置一个 CoordinatorLayout
,其中嵌入了一个 AppBarLayout
,其中包含一个 CollapsingToolbarLayout
,其中包含一个 Toolbar
和一个兄弟 ViewGroup
,例如作为 LinearLayout
。将滑到工具栏后面的是同级 ViewGroup
。另一个关键是在 CollapsingToolbarLayout
上设置适当的滚动标志,如 scroll|exitUntilCollapsed|enterAlways
.
这是结果的简短视频:
这里是 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>
我想在 RecyclerView 上方放置一个视图,该视图随 RecyclerView 一起滚动,并随向下滚动立即向下滚动。我知道这种行为很快 return 但它是为 Listview 实现的。我知道可以使用 CoordinatorLayout 完成一些类似的操作,但所有示例都使用工具栏进行操作。我想要的在 eBay 应用程序中完成。
尝试使用 ScrollView 包裹 RcyclerView 和 QuickReturn 布局。
平滑滚动使用-
recyclerview.setFocusable(false);
recyclerview.setNestedScrollingEnabled(false);
您需要设置一个 CoordinatorLayout
,其中嵌入了一个 AppBarLayout
,其中包含一个 CollapsingToolbarLayout
,其中包含一个 Toolbar
和一个兄弟 ViewGroup
,例如作为 LinearLayout
。将滑到工具栏后面的是同级 ViewGroup
。另一个关键是在 CollapsingToolbarLayout
上设置适当的滚动标志,如 scroll|exitUntilCollapsed|enterAlways
.
这是结果的简短视频:
这里是 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>