ScrollView内部的RecyclerView,某些项目未显示

yww*_*ynm 16 android android-scrollview android-support-library android-recyclerview android-6.0-marshmallow

我在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>
Run Code Online (Sandbox Code Playgroud)

这个RecyclerView项目是一个RelativeLayout,其中有一个EditText和其他的观点.在layout_heightRelativeLayoutEditText既是wrap_content.用户可以在EditText没有任何长度/线条限制的情况下输入,以便每个项目的高度不同.

然后我发现getItemCount()Adapter返回true值但onBindViewHolder()被调用错误的时间(少于它应该),因此不足以显示所有项目.

我发现这只会在我写的时候发生recyclerView.setNestedScrollingEnabled(false).但我不能删除这一行.因为如果我这样做了,RecyclerView它就不会顺畅地滚动,并且与其他内部ScrollViewScrollView自身的观点不一致.

这发生在6.0但不是4.1.

我在此页面与Google进行了沟通:https://code.google.com/p/android/issues/detail?id = 213914他告诉我这是一个错误修复程序RecyclerView.您可以访问该页面,以便更好地理解问题和我的目标(有一个小样本项目可以显示问题).即使是现在我也不同意他,我想解决这个问题.请帮忙,提前谢谢.

yww*_*ynm 75

我找到了自己的解决方案:更换ScrollViewNestedScrollView和保持recyclerView.setNestedScrollingEnabled(false).我不知道这是不是这样NestedScrollView做但它有效.

注意:

  1. NestedScrollView不是孩子ScrollView而是FrameLayout.
  2. 这个解决方案也会带来一些自我模拟的错误adjustResize.

  • 实际上这不是一个好的解决方案.这会导致RecyclerView不再循环使用. (5认同)
  • 帮助我,谢谢,```setNestedScrollingEnabled(false);```对于保持平滑滚动非常重要 (2认同)

小智 5

就我而言,我用RelativeLayout替换了LineaLayout,它解决了问题并且所有项目都已显示。