RecyclerView不会滚动并显示所有项目 [英] RecyclerView that does not scroll and shows all items
问题描述
我在ScrollView中有一个RecyclerView(和其他一些视图).当前,RecyclerView的布局非常小(它显示了其中包含的5个项目中的2个),并且它独立于ScrollView滚动,这显然不是很棒的UX.我想让RecyclerView不滚动并扩展,以便其所有项目都可见.
I have a RecyclerView (and some other views) in a ScrollView. Currently the RecyclerView is laid out as very small (it shows 2 items out of 5 that it contains) and it scrolls independently of the ScrollView, which is obviously not great UX. I would like to get the RecyclerView to not scroll and to extend so that all its items are visible.
(我知道在这种情况下使用RecyclerView是愚蠢的.我之所以这样做,是因为在应用程序中的其他地方,我需要具有滚动等功能的普通RecyclerView,但是具有相同的内容,我不想要重复代码).
(I know it's stupid to use a RecyclerView in this case. I'm only doing this because somewhere else in the app I need a normal RecyclerView with scrolling etc. but the same kind of content, and I don't want to duplicate code).
推荐答案
非常简单,只需将RecyclerView
的高度设置为wrap_content
.
It’s pretty simple, simply set the RecyclerView
’s height to wrap_content
.
您还可以从禁用回收站视图上的嵌套滚动中受益,如下所示:
You might also benefit from disabling nested scrolling on the recycler view, like so:
RecyclerView recycler = (RecyclerView) findViewById(R.id.recycler);
recycler.setNestedScrollingEnabled(false);
这篇关于RecyclerView不会滚动并显示所有项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!