manish
manish

Reputation: 974

Horizontal Recycler View with multiple item at once

I want to show multiple itemview at once like this

enter image description here

I am using recycler view 23.2.1

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

My recycler view xml

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

Corresponding Java code

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

With this configuration I getting only one item at once. Like image below

enter image description here

It seems like wrap_content in recycler view is not working as the space between images are there. Is there anyway to remove the space between the items.

I found one bug related to wrap_contect in recycler view link which is fixed. Not sure if this is causing the problem. Any help to fix this will be appreciated

My row view:

 <?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>

Upvotes: 3

Views: 5309

Answers (1)

tyczj
tyczj

Reputation: 74006

Your parent LinearLayout for your row cannot be match_parent you must use wrap_content for your width or else you will get what you see there.

if you had a vertical recyclerview then you would be using wrap_content for your height and not your width

Upvotes: 5

Related Questions