2017-10-05 184 views
2

我有這樣的回收觀點:RecyclerView GridLayoutManager項目match_parent寬度

<android.support.v7.widget.RecyclerView 
     android:id="@+id/recycler" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

和項目是這樣的:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

<ImageView 
    android:layout_width="100dp" 
    android:layout_height="70dp" 
    android:scaleType="fitCenter" 
    android:layout_margin="10dp" /> 

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:padding="10dp" 
    android:linksClickable="true" /> 

</LinearLayout> 

我在代碼中這樣做是爲了有一個2列的網格:

 GridLayoutManager gridLayoutManager = new GridLayoutManager(context, 2, LinearLayoutManager.VERTICAL,false); 
     _recycler.setLayoutManager(gridLayoutManager); 

我希望每個項目都有可用的「match_parent」空間,事實並非如此!每個項目佔用一半的空間。如何做寬度=「match_parent」的項目和水平滾動的可能性?水平

screen 

|------| 

    ITEM1 - ITEM2 
    ITEM3 - ITEM4 
+0

你想要水平和垂直滾動? – nomag

+0

nop,因爲我想顯示所有沒有垂直滾動的內容。我只是想提供水平滾動顯示項目「隱藏」。 (因爲如果每個項目都顯示在匹配父項中,必須滾動查看其他項) – deveLost

+0

因此,喲要一次顯示一個項目?並水平滾動? –

回答

0

你無法比擬的父母,並將它水平滾動,你必須選擇其中的一個辦法:

我想是這樣的。爲了實現你想要的,你必須使用像FiewFlipper或標籤。

+0

我不明白爲什麼!表格佈局可以顯示符合°_parent的項目並水平滾動。我想使用回收器視圖,而不是我的表格佈局來獲得性能,但是......如果不可能:( – deveLost

+0

)你說你不需要垂直滾動,這意味着你只在網格中有幾個項目?因此RecyclerView不會提高性能,只有當您的清單大於屏幕上的任何時間時纔會有所幫助。 – meeeee

+0

Nop,我不想讓垂直滾動,我將顯示所有內容因爲這是一個特定的情況,所以是的,Recyclerview會提高性能,我認爲:( – deveLost

相關問題