3

我想像这样一次显示多个 itemview

在此处输入图像描述

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

我在回收站视图链接中发现了一个与 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>
4

1 回答 1

6

您的行的父 LinearLayout 不能是match_parent您必须使用wrap_content的宽度,否则您将得到您在那里看到的内容。

如果你有一个垂直回收视图,那么你将使用wrap_content你的高度而不是你的宽度

于 2016-07-06T18:27:33.957 回答