【发布时间】:2016-10-30 16:57:28
【问题描述】:
我在 ScrollView 中有一个这样的 RecyclerView:
<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,没有任何长度/行的限制,这样每个项目的高度都是不同的。
然后我发现Adapter中的getItemCount()返回真值,但onBindViewHolder()被调用的时间错误(少于应有的时间),因此不足以显示所有项目。
我发现只有写recyclerView.setNestedScrollingEnabled(false) 才会发生这种情况。但我不能删除这条线。因为如果我这样做了,RecyclerView 将不会平滑滚动,并且与 ScrollView 和 ScrollView 本身内部的其他视图不协调。
这发生在 6.0 而不是 4.1。
我在此页面上与 Google 进行了交流:https://code.google.com/p/android/issues/detail?id=213914,他告诉我这是针对 RecyclerView 的错误修复。您可以访问该页面,以便更好地理解问题和我的目标(有一个小示例项目可以在那里显示问题)。我现在也不同意他的观点,我想解决这个问题。请帮忙,提前谢谢。
【问题讨论】:
-
尝试在滚动视图中设置android:fillViewport="true"
-
@LucasPaolillo 好吧,它没有帮助。
-
用android:fillViewPort="true",将线性布局高度改为match_parent
-
@LucasPaolillo 还是没用。
标签: android android-recyclerview android-support-library android-6.0-marshmallow android-scrollview