android – 如何使recyclerview显示所有项目,不能滚动

前端之家收集整理的这篇文章主要介绍了android – 如何使recyclerview显示所有项目,不能滚动前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在制作一个应用程序,以1视图显示所有产品.我希望recyclerview显示所有项目并且无法滚动,只需滚动父视图(ScrollView).但问题是不能使回收者的高度包裹所有内容.

–>>I want like this

这是我的代码


  1. <TextView
  2. android:text="Best seller:"
  3. android:layout_width="match_parent"
  4. android:layout_height="wrap_content"
  5. android:id="@+id/textView4"
  6. android:textColor="#3f3f3f"
  7. android:textSize="18sp" />
  8.  
  9. <android.support.v7.widget.RecyclerView
  10. android:layout_width="match_parent"
  11. android:scrollbars="horizontal"
  12. android:id="@+id/rv_bestSeller"
  13. android:layout_height="200dp" />
  14.  
  15. <TextView
  16. android:text="New Product"
  17. android:layout_width="match_parent"
  18. android:layout_height="wrap_content"
  19. android:id="@+id/textView5"
  20. android:textSize="18sp"
  21. android:textColor="#3f3f3f" />
  22.  
  23. <android.support.v7.widget.RecyclerView
  24. android:layout_width="match_parent"
  25. android:scrollbars="horizontal"
  26. android:layout_height="200dp"
  27. android:id="@+id/rv_newProduct"/>
  28.  
  29. <TextView
  30. android:text="All Product"
  31. android:layout_width="match_parent"
  32. android:layout_height="wrap_content"
  33. android:id="@+id/textView6"
  34. android:textSize="18sp"
  35. android:textColor="#3f3f3f" />
  36. <android.support.v7.widget.RecyclerView
  37. android:layout_width="match_parent"
  38. android:layout_height="wrap_content"
  39. android:id="@+id/rv_allProduct" />
  40. </LinearLayout>
  41. </ScrollView>

–>>But the space is so small

解决方法

这样做是不好的做法,如果你这样做是因为标题使用了这个库
https://github.com/emilsjolander/StickyListHeaders

它会给你标题,你不需要里面有列表的滚动视图.

如果你真的想以这种方式继续使用NestedScrollView而不是常规的Scrollview

https://developer.android.com/reference/android/support/v4/widget/NestedScrollView.html

这将允许你像你想要的那样禁用嵌套滚动

猜你在找的Android相关文章