ScrollView内的RecyclerView,未显示某些项目 [英] RecyclerView inside ScrollView, some items are not shown
问题描述
我在ScrollView中有一个这样的RecyclerView:
I had a RecyclerView in ScrollView like this:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--other stuff-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"/>
</LinearLayout>
<!--other stuff-->
</ScrollView>
RecyclerView
的项是RelativeLayout
,其中有一个EditText
和其他视图.该RelativeLayout
和EditText
的layout_height
均为wrap_content
.用户可以输入EditText
而不受长度/线的限制,从而使每个项目的高度都不同.
And the RecyclerView
's item is a RelativeLayout
, inside of which there is an EditText
and other views. The layout_height
of that RelativeLayout
and EditText
is both wrap_content
. User can input into that EditText
without any limit of length/lines so that each item's height is different.
然后我发现Adapter
中的getItemCount()
返回真实值,但是onBindViewHolder()
被调用错误的时间(少于应该的时间),因此不足以显示所有项目.
Then I found that getItemCount()
in Adapter
returns true value but onBindViewHolder()
is called of wrong times(less than it should be), thus not enough to show all items.
我发现只有当我写recyclerView.setNestedScrollingEnabled(false)
时,这种情况才会发生.但我无法删除此行.因为如果这样做,RecyclerView
将无法平滑滚动,并且与ScrollView
和ScrollView
本身内部的其他视图不协调.
I found that this will happen only if I wrote recyclerView.setNestedScrollingEnabled(false)
. But I cannot remove this line. Because if I did so, the RecyclerView
won't scroll smoothly and is not harmonious with other views inside ScrollView
and ScrollView
itself.
这在6.0上发生,但在4.1上没有发生.
This occurs on 6.0 but not on 4.1.
我在以下页面上与Google进行了交流: https://code. google.com/p/android/issues/detail?id=213914 ,他告诉我这是RecyclerView
的错误修复.您可以访问该页面,以便更好地理解问题和我的目标(这里有一个小的示例项目来显示问题).我什至现在都不同意他的观点,我想解决这个问题.请帮忙,谢谢您.
I communicated with Google at this page: https://code.google.com/p/android/issues/detail?id=213914 and he told me this is a bug fix for RecyclerView
. You can visit that page so that you can understand the question and my goal better(There is a small sample project to show the problem there). I don't agree with him even now and I want to solve the problem. Please help, thank you in advance.
推荐答案
我自己找到了解决方案:用NestedScrollView
替换ScrollView
并保留recyclerView.setNestedScrollingEnabled(false)
.我不知道这是否是NestedScrollView
的目的,但它可以工作.
I found the solution myself: replace ScrollView
with NestedScrollView
and keep recyclerView.setNestedScrollingEnabled(false)
. I don't know if this is what NestedScrollView
is made for but it works.
注意:
-
NestedScrollView
不是ScrollView
的子级,而是FrameLayout
的子级. - 此解决方案还会通过自模拟
adjustResize
带来一些错误.
NestedScrollView
is not a child ofScrollView
but ofFrameLayout
.- This solution will also bring some bugs with self-simulated
adjustResize
.
这篇关于ScrollView内的RecyclerView,未显示某些项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!