一次使用多个项目的水平回收视图

我想像这样一次显示多个项目视图

?

?

我正在使用回收器视图23.2.1

compile 'com.android.support:recyclerview-v7:23.2.1'

我的回收者视图xml

       <android.support.v7.widget.RecyclerView
            android:id="@+id/gallary"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:scrollbars="horizontal" />

对应的Java代码

 mRecyclerView = (RecyclerView) findViewById(R.id.gallary);
 mLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
 mRecyclerView.setLayoutManager(mLayoutManager);

使用这种配置,我一次只能得到一件物品。如下图所示

?

?

在回收商的视图中,wrap_content似乎没有工作,因为图像之间的空间在那里。有没有办法去掉两项之间的空格。

我在回收器视图link中发现了一个与wrap_contect相关的错误,这个错误已经修复。不确定是不是这导致了问题。任何帮助解决这个问题的人都将不胜感激。

我的行视图:

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

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/facebook" />

        <TextView
            android:id="@+id/titletv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/image"
            android:layout_centerHorizontal="true"
            android:text="Testing"
            android:textSize="@dimen/fourteen_sp" />


        <ProgressBar
            android:id="@+id/mainimgloading"
            android:layout_width="24dp"
            android:layout_height="24dp"
            android:layout_centerInParent="true"
            android:layout_gravity="center" />


    </RelativeLayout>

</LinearLayout>

转载请注明出处:http://www.sthongjia.com/article/20230526/1306398.html