简体   繁体   English

如何禁用recyclerview的内部滚动但保持外部列表滚动? (如材料设计指南中所示)

[英]How to disable internal scrolling of a recyclerview but maintain outer list scrolling? (as shown in the material design guidelines)

Here is what I am trying to achieve: Link to google's material design guide 这是我要实现的目标: 链接到Google的材料设计指南

https://material.io/design/components/cards.html#behavior

In my case I have multiple cards in a scrollView, which contains a linear layout. 在我的情况下,scrollView中有多张卡片,其中包含线性布局。 I did not use a recycler view because the number of cards is always about the same (below 10). 我之所以没有使用回收站视图,是因为卡片的数量总是大约相同(低于10)。 One of the cards contains two recyclerviews showing a list of for example comments. 其中一张卡片包含两个recyclerviews,其中显示了例如评论的列表。 The problem is that I can't find a way to disable scrolling of the internal recyclerview without causing it to not scroll at all and show incomplete data. 问题是我无法找到一种方法来禁用内部recyclerview的滚动而不导致它根本不滚动并显示不完整的数据。

Thanks for your help! 谢谢你的帮助!

Use a NestedScrollView and put your RecyclerView inside it. 使用NestedScrollView并将RecyclerView放入其中。

If you wish the RecyclerView to become a scrolling part of your NestedScrollView, set nested scrolling to false. 如果您希望RecyclerView成为NestedScrollView的滚动部分,请将嵌套滚动设置为false。

NestedScrollView nestedScrollView = findViewById(R.id.myNestedScrollView);
nestedScrollView.setNestedScrollingEnabled(false);

If you want an independent scroll you don't need to do anything since nested scrolling is set to true by default. 如果您想进行独立滚动,则无需执行任何操作,因为默认情况下嵌套滚动设置为true。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM