2016-12-11 114 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