我正在制作一个应用程序,以1视图显示所有产品.我希望recyclerview显示所有项目并且无法滚动,只需滚动父视图(ScrollView).但问题是不能使回收者的高度包裹所有内容.
这是我的代码:
- <TextView
- android:text="Best seller:"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/textView4"
- android:textColor="#3f3f3f"
- android:textSize="18sp" />
- <android.support.v7.widget.RecyclerView
- android:layout_width="match_parent"
- android:scrollbars="horizontal"
- android:id="@+id/rv_bestSeller"
- android:layout_height="200dp" />
- <TextView
- android:text="New Product"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/textView5"
- android:textSize="18sp"
- android:textColor="#3f3f3f" />
- <android.support.v7.widget.RecyclerView
- android:layout_width="match_parent"
- android:scrollbars="horizontal"
- android:layout_height="200dp"
- android:id="@+id/rv_newProduct"/>
- <TextView
- android:text="All Product"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/textView6"
- android:textSize="18sp"
- android:textColor="#3f3f3f" />
- <android.support.v7.widget.RecyclerView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/rv_allProduct" />
- </LinearLayout>
- </ScrollView>
解决方法
这样做是不好的做法,如果你这样做是因为标题使用了这个库
https://github.com/emilsjolander/StickyListHeaders
https://github.com/emilsjolander/StickyListHeaders
它会给你标题,你不需要里面有列表的滚动视图.
如果你真的想以这种方式继续使用NestedScrollView而不是常规的Scrollview
https://developer.android.com/reference/android/support/v4/widget/NestedScrollView.html
这将允许你像你想要的那样禁用嵌套滚动