2016-09-27 139 views
-2

我想結果是這樣的:RecyclerView在NestedScrollView與水平scolling

enter image description here

它可以做水平滾動

但事實上,這樣的下面:

enter image description here

不能顯示所有項目,而不是橫向佈局。

誰能幫幫我?謝謝。其他方式可以達到我想要的結果嗎?

+0

看看這裏:http://stackoverflow.com/editing-help #images,然後編輯或提出正確放置圖像的新問題。如果一切正常,請務必在預覽時檢查。 – emiliopedrollo

回答

0

您需要將佈局管理器添加到RecylerView。

LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false); 
    recylcerView.setLayoutManager(layoutManager); 

這將使RecylerView水平。

+0

我設置了LinearLayoutManager.HORIZONTAL,但RecyclerView在NestedScrollView顯示垂直,不是水平 – Seven

0

要將recyclerView設置爲水平scrollView,您可以使用LinearLayoutManager。默認情況下它會設置垂直滾動行爲。

LinearLayoutManager layout = new LinearLayoutManager(getActivity(), 0, false);//0 Horizontal , 1 vertical 
    recyclerView.setLayoutManager(layout); 

在layout.xml

<android.support.v7.widget.RecyclerView 
       android:id="@+id/yourRecyclerView" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/layout_past_round_header" 
       android:layout_centerInParent="true" 
       android:overScrollMode="never" /> 

在NestedScrollView添加此

android:fillViewport="true" 
+0

沒有效果,但顯示垂直 – Seven

相關問題