2017-10-05 185 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

相关问题