一次包含多个项目的水平回收器视图

Horizontal Recycler View with multiple item at once

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

我正在使用回收站视图 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 在回收站视图中不起作用,因为图像之间存在 space。无论如何要删除项目之间的 space 。

我在回收站视图 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>

你的行的父 LinearLayout 不能是 match_parent 你必须使用 wrap_content 作为你的宽度,否则你会得到你在那里看到的东西。

如果你有一个垂直的 recyclerview 那么你会使用 wrap_content 作为你的高度而不是你的宽度