嵌套RecyclerView中的滚动行为与水平滚动 [英] Scroll behavior in nested RecyclerView with horizontal scroll
问题描述
我必须在每个项目中创建带有嵌套水平RecyclerView
的垂直RecyclerView
.一切都在CoordinatorLayout
之内.当我通过点击外部滚动滚动时,嵌套的RecyclerView工具栏会隐藏,但是当我通过点击嵌套滚动滚动父回收器时,一个工具栏会保留.
I have to create vertical RecyclerView
with nested horizontal RecyclerView
in every item. Everything is within CoordinatorLayout
. When I scroll by tapping outside nested RecyclerView toolbar hides, but when I scroll parent Recycler by tapping on nested one toolbar stays.
任何帮助将不胜感激.
这是我的xml布局:
main_activity.xml:
main_activity.xml:
<android.support.design.widget.CoordinatorLayout
...>
<FrameLayout
android:id="@+id/fragment_frame"
...
android:fitsSystemWindows="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<android.support.design.widget.AppBarLayout
...
android:fitsSystemWindows="true"
android:id="@+id/appbar_layout">
<include layout="@layout/toolbar"/>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
这是toolbar.xml:
Here is toolbar.xml :
<android.support.v7.widget.Toolbar
android:id="@+id/main_toolbar"
...
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|enterAlways">
<TextView .../>
</android.support.v7.widget.Toolbar>
fragment.xml:
fragment.xml:
<android.support.v7.widget.RecyclerView
...
android:scrollbars="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
还有recycler_view_item.xml:
And recycler_view_item.xml:
<RelativeLayout ...>
<TextView .../>
<!-- fixme(CullyCross) fix bug with hiding toolbar -->
<android.support.v7.widget.RecyclerView
...
android:scrollbars="horizontal"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
</RelativeLayout>
谢谢,
安东
推荐答案
根据要求,这是到目前为止我发现足够好的解决方案:
As requested here is the solution I found good enough so far:
在我的情况下,我有一个nestedScrollView
,其中4个RecyclerView
设置为在内部水平滚动.对于每个RecyclerView
,我都以编程方式完成了此操作:
In my case I have a nestedScrollView
with 4 RecyclerView
s set to scroll horizontally inside. For each of those RecyclerView
s I have done this programatically:
restaurantsRecylerView.setHasFixedSize(true);
restaurantsRecylerView.setNestedScrollingEnabled(false);
您可能不希望fixedSize,不确定它是否会有所不同,我的列表始终为25,因此我可以使用它来提高性能.完成此操作后,即使我触摸了recyclerViews,我也可以毫无问题地滚动
You probably don't want the fixedSize, not sure if it will make any difference, my list is always 25 so I can use that for performance. After having done this I can scroll without issues even when I touch on the recyclerViews
希望有帮助
这篇关于嵌套RecyclerView中的滚动行为与水平滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!