2016-12-11 210 views
3

我正在制作应用程序以显示1视图中的所有产品。我想recyclerview显示所有项目并且不能滚动,只需滚动父视图(ScrollView)即可。但问题是无法使回收站的高度包裹所有内容。如何让recyclerview显示所有项目并且不能滚动

-->>I want like this

这是我的代码:

<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> 

-->>But the space is so small

回答

5

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

它会给你头,你不需要滚动视图里面的列表。

,如果你真的想继续使用这种方式,而不是常规的滚动型NestedScrollView

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

,这将让您分别关闭嵌套滚动像你想使用

+0

nestedscrollview解决我的问题 –

+0

使用setNestedScrollingEnabled (假); – yanivtwin

+2

NestedScrollView和setNestedScrollingEnabled(false)修复了它。竖起大拇指。愿原力与你同在。 – ralphgabb