[英]NestedScrolling with NestedScrollView, RecyclerView (Horizontal), inside a CoordinatorLayout
[英]CoordinatorLayout with NestedScrollView and Horizontal Scrolling RecyclerView
我有一個帶有AppBarLayout的CoordinatorLayout,可以在滾動時折疊/展開工具欄。 內容視圖是帶有RecyclerViews(水平滾動)的NestedScrollView和其他一些沒有scrollview的視圖。 非常類似於Airbnb應用程序。
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include layout="@layout/toolbar_flat" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/newstedScrollView"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/consistentGreyWhite"
android:paddingBottom="@dimen/activity_vertical_margin"
android:clipToPadding="false"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/home_slider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/consistentWhite"
android:clipToPadding="false"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="14dp"
android:paddingRight="14dp"
android:paddingTop="@dimen/activity_vertical_margin"
/>
<... other elements ...>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
如果我滾動元素沒有滾動視圖,工具欄折疊/展開工作。 但是如果我在RecyclerView上執行滾動(垂直),則工具欄無法按預期工作。 似乎RecyclerViews不會將滾動事件傳遞給CoordinatorLayout。
我也有這個問題。
將此屬性添加到NestedScrollView
標記
app:layout_behavior="@string/appbar_scrolling_view_behavior"
另外,對片段或活動中的每個recyclerView對象執行以下操作。 並且在你的適配器中,如果你正在嵌套recycler_views'。
recyclerView.setNestedScrollingEnabled(false);
將此屬性添加到您的Recycler View
。
app:layout_behavior="@string/appbar_scrolling_view_behavior"
您也可以將其添加到Recycler View
。
mRecyclerView.setNestedScrollingEnabled(false);
像這樣。
<android.support.v7.widget.RecyclerView
android:id="@+id/home_slider"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
NestedScrollView
與android:fillViewport="true"
也是一樣的。
您可以使用android:fillViewport="true"
來使NestedScrollView
測量RecyclerView
。
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.